diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..63fe03e --- /dev/null +++ b/config_test.go @@ -0,0 +1,52 @@ +package corbado + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestNewConfig_Success(t *testing.T) { + projectID := "pro-12345678" + secret := "mysupersecret" + + cfg, err := NewConfig(projectID, secret) + require.NoError(t, err) + + assert.Equal(t, projectID, cfg.ProjectID) + assert.Equal(t, secret, cfg.APISecret) + assert.Equal(t, fmt.Sprintf(configDefaultFrontendAPI, projectID), cfg.FrontendAPI) + assert.Equal(t, configDefaultBackendAPI, cfg.BackendAPI) + assert.Equal(t, configDefaultShortSessionCookieName, cfg.ShortSessionCookieName) + assert.Equal(t, configDefaultCacheMaxAge, cfg.CacheMaxAge) +} + +func TestNewConfig_Failure(t *testing.T) { + tests := []struct { + name string + projectID string + secret string + }{ + { + name: "empty projectID and secret", + }, + { + name: "empty projectID", + secret: "secret", + }, + { + name: "empty secret", + projectID: "pro-12345678", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + cfg, err := NewConfig(test.projectID, test.secret) + assert.Nil(t, cfg) + assert.ErrorContains(t, err, "given value '' is too short") + }) + } +} diff --git a/go.mod b/go.mod index 4548957..6b0037f 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,13 @@ require ( github.com/golang-jwt/jwt/v4 v4.4.2 github.com/oapi-codegen/runtime v1.0.0 github.com/pkg/errors v0.9.1 + github.com/stretchr/testify v1.8.4 ) require ( github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/uuid v1.3.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5d46542..46eb071 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,7 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deepmap/oapi-codegen v1.16.2 h1:xGHx0dNqYfy9gE8a7AVgVM8Sd5oF9SEgePzP+UPAUXI= github.com/deepmap/oapi-codegen v1.16.2/go.mod h1:rdYoEA2GE+riuZ91DvpmBX9hJbQpuY9wchXpfQ3n+ho= github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= @@ -23,4 +24,8 @@ github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKk github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=