Skip to content

Commit

Permalink
test: reduce ut
Browse files Browse the repository at this point in the history
  • Loading branch information
baerwang committed Aug 10, 2023
1 parent 3ea47a2 commit 46612f7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions pkg/security/tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func TestSimpleTenantManager(t *testing.T) {
var (
tm = newSimpleTenantManager()
tm = DefaultTenantManager()
ok bool
)

Expand All @@ -43,9 +43,9 @@ func TestSimpleTenantManager(t *testing.T) {
assert.Empty(t, cluster)

tm.PutCluster("fake-tenant", "fake-cluster")
tm.PutUser("fake-tenant", &config.User{
Username: "fake-user",
})
tm.PutUser("fake-tenant", &config.User{Username: "fake-user"})
tm.PutUser("arana-tenant", &config.User{Username: "arana-user"})
assert.Equal(t, tm.GetTenants(), []string{"fake-tenant", "arana-tenant"})

var (
user *config.User
Expand All @@ -61,10 +61,25 @@ func TestSimpleTenantManager(t *testing.T) {
assert.NotNil(t, user)
assert.Equal(t, "fake-user", user.Username)

users, b := tm.GetUsers("fake-tenant")
assert.Equal(t, b, true)
assert.Equal(t, users, []*config.User{{Username: "fake-user"}})

clusters = tm.GetClusters("fake-tenant")
assert.Len(t, clusters, 1)
assert.Equal(t, []string{"fake-cluster"}, clusters)

tm.RemoveUser("fake-tenant", "fake-user")
tm.RemoveCluster("fake-tenant", "fake-cluster")

users, b = tm.GetUsers("fake-user")
assert.Equal(t, b, false)
assert.Empty(t, users)

tm.RemoveUser("real-tenant", "real-user")
tm.RemoveCluster("real-tenant", "real-cluster")

supervisor := &config.User{Username: "arana", Password: "arana"}
tm.SetSupervisor(supervisor)
assert.Equal(t, tm.GetSupervisor(), supervisor)
}

0 comments on commit 46612f7

Please sign in to comment.