Skip to content

Commit

Permalink
mock config
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Wiesner committed May 13, 2023
1 parent 6cf43c0 commit 7c7d390
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/handler/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"bytes"
"errors"
"github.com/bakito/sealed-secrets-web/pkg/config"
"net/http"
"net/http/httptest"

Expand All @@ -21,15 +22,18 @@ var _ = Describe("Handler ", func() {
mock *gomock.Controller
sealer *seal.MockSealer
h *Handler
cfg *config.Config
)
BeforeEach(func() {
gin.SetMode(gin.ReleaseMode)
recorder = httptest.NewRecorder()
c, _ = gin.CreateTestContext(recorder)
mock = gomock.NewController(GinkgoT())
sealer = seal.NewMockSealer(mock)
cfg = &config.Config{}
h = &Handler{
sealer: sealer,
cfg: cfg,
}
})

Expand Down Expand Up @@ -60,13 +64,14 @@ var _ = Describe("Handler ", func() {
})

It("should return an error if certURL is used", func() {
cfg.SealedSecrets.CertURL = "http://sealed-secrets/v1/cert.pem"
c.Request, _ = http.NewRequest("POST", "/v1/validate", bytes.NewReader([]byte(stringDataAsYAML)))
c.Request.Header.Set("Content-Type", "application/x-yaml")

sealer.EXPECT().Validate(gomock.Any(), gomock.Any()).Return(errors.New("Validation failed"))
h.Validate(c)

Ω(recorder.Code).Should(Equal(http.StatusBadRequest))
Ω(recorder.Body.String()).Should(Equal("Validation failed"))
Ω(recorder.Code).Should(Equal(http.StatusConflict))
Ω(recorder.Body.String()).Should(Equal("validate can't be used with CertURL (http://sealed-secrets/v1/cert.pem)"))
Ω(recorder.Header().Get("Content-Type")).Should(Equal("text/plain"))
})
})
Expand Down

0 comments on commit 7c7d390

Please sign in to comment.