usergroups_test.go 1020 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package pro
  2. import (
  3. "testing"
  4. "github.com/gravitl/netmaker/models/promodels"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestUserGroupLogic(t *testing.T) {
  8. initialize()
  9. t.Run("User Groups initialized successfully", func(t *testing.T) {
  10. err := InitializeGroups()
  11. assert.Nil(t, err)
  12. })
  13. t.Run("Check for default group", func(t *testing.T) {
  14. groups, err := GetUserGroups()
  15. assert.Nil(t, err)
  16. var hasdefault bool
  17. for k := range groups {
  18. if string(k) == DEFAULT_ALLOWED_GROUPS {
  19. hasdefault = true
  20. }
  21. }
  22. assert.True(t, hasdefault)
  23. })
  24. t.Run("User Groups created successfully", func(t *testing.T) {
  25. err := InsertUserGroup(promodels.UserGroupName("group1"))
  26. assert.Nil(t, err)
  27. err = InsertUserGroup(promodels.UserGroupName("group2"))
  28. assert.Nil(t, err)
  29. })
  30. t.Run("User Groups deleted successfully", func(t *testing.T) {
  31. err := DeleteUserGroup(promodels.UserGroupName("group1"))
  32. assert.Nil(t, err)
  33. assert.False(t, DoesUserGroupExist(promodels.UserGroupName("group1")))
  34. })
  35. }