Skip to content

Commit

Permalink
Simple unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
corbadovych committed Nov 16, 2023
1 parent 405bd47 commit c0ee740
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
52 changes: 52 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -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")
})
}
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=

0 comments on commit c0ee740

Please # to comment.