Skip to content

Commit

Permalink
Add test with github payload
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianrakel authored and bastelfreak committed Jun 22, 2023
1 parent 08c773b commit 85fab11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/helpers/yaml/webhook.queue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
server:
queue:
enabled: true
max_concurrent_jobs: 10
max_history_items: 20
34 changes: 34 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package server

import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/voxpupuli/webhook-go/config"
"github.com/voxpupuli/webhook-go/lib/queue"
)

func TestPingRoute(t *testing.T) {
Expand All @@ -18,3 +22,33 @@ func TestPingRoute(t *testing.T) {
assert.Equal(t, 200, w.Code)
assert.Equal(t, "{\"message\":\"running\"}", w.Body.String())
}

func TestQueue(t *testing.T) {
mCfg := "../lib/helpers/yaml/webhook.queue.yaml"
config.Init(&mCfg)

queue.Work()

router := NewRouter()

payloadFile, err := os.Open("../lib/parsers/json/github/push.json")
if err != nil {
t.Fatal(err)
}

w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodPost, "/api/v1/r10k/environment", payloadFile)
req.Header.Add("X-GitHub-Event", "push")

router.ServeHTTP(w, req)

var queueItem queue.QueueItem
err = json.Unmarshal(w.Body.Bytes(), &queueItem)
if err != nil {
t.Fatal(err)
}

assert.Equal(t, 202, w.Code)
assert.Equal(t, "simple-tag", queueItem.Name)
assert.Equal(t, "added", queueItem.State)
}

0 comments on commit 85fab11

Please sign in to comment.