Skip to content

Commit

Permalink
add tests for admin Store and DataService
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal authored and umputun committed Nov 4, 2023
1 parent 618c267 commit cd481d4
Show file tree
Hide file tree
Showing 4 changed files with 461 additions and 1 deletion.
3 changes: 3 additions & 0 deletions backend/app/store/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
log "github.com/go-pkgz/lgr"
)

// NOTE: matryer/moq should be installed globally and works with `go generate ./...`
//go:generate moq --out admin_mock.go . Store

// Store defines interface returning admins info for given site
type Store interface {
Key(siteID string) (key string, err error)
Expand Down
256 changes: 256 additions & 0 deletions backend/app/store/admin/admin_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions backend/app/store/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import (
"github.com/stretchr/testify/assert"
)

func TestStaticStore_StoreWithoutSites(t *testing.T) {
var ks Store = NewStaticKeyStore("key123")
enabled, err := ks.Enabled("any")
assert.NoError(t, err)
assert.True(t, enabled, "on empty store all sites are enabled")
assert.NoError(t, ks.OnEvent("test", EvCreate), "static store does nothing OnEvent")

// empty key
ks = NewStaticKeyStore("")
key, err := ks.Key("any")
assert.Error(t, err, "empty key")
assert.Empty(t, key)
}

func TestStaticStore_Get(t *testing.T) {
var ks Store = NewStaticStore("key123", []string{"s1", "s2", "s3"},
[]string{"123", "xyz"}, "aa@example.com")
Expand Down
Loading

0 comments on commit cd481d4

Please sign in to comment.