mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
feat(stacks): support automated sync for stacks [EE-248] (#5340)
This commit is contained in:
parent
5fe90db36a
commit
bcccdfb669
94 changed files with 2680 additions and 469 deletions
59
api/http/handler/stacks/webhook_invoke_test.go
Normal file
59
api/http/handler/stacks/webhook_invoke_test.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package stacks
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
|
||||
"github.com/portainer/portainer/api/bolt/bolttest"
|
||||
)
|
||||
|
||||
func TestHandler_webhookInvoke(t *testing.T) {
|
||||
store, teardown := bolttest.MustNewTestStore(true)
|
||||
defer teardown()
|
||||
|
||||
webhookID := newGuidString(t)
|
||||
store.StackService.CreateStack(&portainer.Stack{
|
||||
AutoUpdate: &portainer.StackAutoUpdate{
|
||||
Webhook: webhookID,
|
||||
},
|
||||
})
|
||||
|
||||
h := NewHandler(nil)
|
||||
h.DataStore = store
|
||||
|
||||
t.Run("invalid uuid results in http.StatusBadRequest", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := newRequest("notuuid")
|
||||
h.Router.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusBadRequest, w.Code)
|
||||
})
|
||||
t.Run("registered webhook ID in http.StatusNoContent", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := newRequest(webhookID)
|
||||
h.Router.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusNoContent, w.Code)
|
||||
})
|
||||
t.Run("unregistered webhook ID in http.StatusNotFound", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := newRequest(newGuidString(t))
|
||||
h.Router.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func newGuidString(t *testing.T) string {
|
||||
uuid, err := uuid.NewV4()
|
||||
assert.NoError(t, err)
|
||||
|
||||
return uuid.String()
|
||||
}
|
||||
|
||||
func newRequest(webhookID string) *http.Request {
|
||||
return httptest.NewRequest(http.MethodPost, "/stacks/webhooks/"+webhookID, nil)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue