GH-12888 Modify api4/config_test.go to use testify (#12946)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
6a906e91ad
Коммит
5b89cdcb6b
@@ -25,31 +25,26 @@ func TestGetConfig(t *testing.T) {
|
||||
require.NotEqual(t, "", cfg.TeamSettings.SiteName)
|
||||
|
||||
if *cfg.LdapSettings.BindPassword != model.FAKE_SETTING && len(*cfg.LdapSettings.BindPassword) != 0 {
|
||||
t.Fatal("did not sanitize properly")
|
||||
}
|
||||
if *cfg.FileSettings.PublicLinkSalt != model.FAKE_SETTING {
|
||||
t.Fatal("did not sanitize properly")
|
||||
require.FailNow(t, "did not sanitize properly")
|
||||
}
|
||||
require.Equal(t, model.FAKE_SETTING, *cfg.FileSettings.PublicLinkSalt, "did not sanitize properly")
|
||||
|
||||
if *cfg.FileSettings.AmazonS3SecretAccessKey != model.FAKE_SETTING && len(*cfg.FileSettings.AmazonS3SecretAccessKey) != 0 {
|
||||
t.Fatal("did not sanitize properly")
|
||||
require.FailNow(t, "did not sanitize properly")
|
||||
}
|
||||
if *cfg.EmailSettings.SMTPPassword != model.FAKE_SETTING && len(*cfg.EmailSettings.SMTPPassword) != 0 {
|
||||
t.Fatal("did not sanitize properly")
|
||||
require.FailNow(t, "did not sanitize properly")
|
||||
}
|
||||
if *cfg.GitLabSettings.Secret != model.FAKE_SETTING && len(*cfg.GitLabSettings.Secret) != 0 {
|
||||
t.Fatal("did not sanitize properly")
|
||||
}
|
||||
if *cfg.SqlSettings.DataSource != model.FAKE_SETTING {
|
||||
t.Fatal("did not sanitize properly")
|
||||
}
|
||||
if *cfg.SqlSettings.AtRestEncryptKey != model.FAKE_SETTING {
|
||||
t.Fatal("did not sanitize properly")
|
||||
require.FailNow(t, "did not sanitize properly")
|
||||
}
|
||||
require.Equal(t, model.FAKE_SETTING, *cfg.SqlSettings.DataSource, "did not sanitize properly")
|
||||
require.Equal(t, model.FAKE_SETTING, *cfg.SqlSettings.AtRestEncryptKey, "did not sanitize properly")
|
||||
if !strings.Contains(strings.Join(cfg.SqlSettings.DataSourceReplicas, " "), model.FAKE_SETTING) && len(cfg.SqlSettings.DataSourceReplicas) != 0 {
|
||||
t.Fatal("did not sanitize properly")
|
||||
require.FailNow(t, "did not sanitize properly")
|
||||
}
|
||||
if !strings.Contains(strings.Join(cfg.SqlSettings.DataSourceSearchReplicas, " "), model.FAKE_SETTING) && len(cfg.SqlSettings.DataSourceSearchReplicas) != 0 {
|
||||
t.Fatal("did not sanitize properly")
|
||||
require.FailNow(t, "did not sanitize properly")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,17 +56,13 @@ func TestReloadConfig(t *testing.T) {
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
ok, resp := Client.ReloadConfig()
|
||||
CheckForbiddenStatus(t, resp)
|
||||
if ok {
|
||||
t.Fatal("should not Reload the config due no permission.")
|
||||
}
|
||||
require.False(t, ok, "should not Reload the config due no permission.")
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
ok, resp := th.SystemAdminClient.ReloadConfig()
|
||||
CheckNoError(t, resp)
|
||||
if !ok {
|
||||
t.Fatal("should Reload the config")
|
||||
}
|
||||
require.True(t, ok, "should Reload the config")
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
@@ -79,9 +70,7 @@ func TestReloadConfig(t *testing.T) {
|
||||
|
||||
ok, resp := Client.ReloadConfig()
|
||||
CheckForbiddenStatus(t, resp)
|
||||
if ok {
|
||||
t.Fatal("should not Reload the config due no permission.")
|
||||
}
|
||||
require.False(t, ok, "should not Reload the config due no permission.")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -245,31 +234,28 @@ func TestGetEnvironmentConfig(t *testing.T) {
|
||||
envConfig, resp := SystemAdminClient.GetEnvironmentConfig()
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if serviceSettings, ok := envConfig["ServiceSettings"]; !ok {
|
||||
t.Fatal("should've returned ServiceSettings")
|
||||
} else if serviceSettingsAsMap, ok := serviceSettings.(map[string]interface{}); !ok {
|
||||
t.Fatal("should've returned ServiceSettings as a map")
|
||||
} else {
|
||||
if siteURL, ok := serviceSettingsAsMap["SiteURL"]; !ok {
|
||||
t.Fatal("should've returned ServiceSettings.SiteURL")
|
||||
} else if siteURLAsBool, ok := siteURL.(bool); !ok {
|
||||
t.Fatal("should've returned ServiceSettings.SiteURL as a boolean")
|
||||
} else if !siteURLAsBool {
|
||||
t.Fatal("should've returned ServiceSettings.SiteURL as true")
|
||||
}
|
||||
serviceSettings, ok := envConfig["ServiceSettings"]
|
||||
require.True(t, ok, "should've returned ServiceSettings")
|
||||
|
||||
if enableCustomEmoji, ok := serviceSettingsAsMap["EnableCustomEmoji"]; !ok {
|
||||
t.Fatal("should've returned ServiceSettings.EnableCustomEmoji")
|
||||
} else if enableCustomEmojiAsBool, ok := enableCustomEmoji.(bool); !ok {
|
||||
t.Fatal("should've returned ServiceSettings.EnableCustomEmoji as a boolean")
|
||||
} else if !enableCustomEmojiAsBool {
|
||||
t.Fatal("should've returned ServiceSettings.EnableCustomEmoji as true")
|
||||
}
|
||||
}
|
||||
serviceSettingsAsMap, ok := serviceSettings.(map[string]interface{})
|
||||
require.True(t, ok, "should've returned ServiceSettings as a map")
|
||||
|
||||
if _, ok := envConfig["TeamSettings"]; ok {
|
||||
t.Fatal("should not have returned TeamSettings")
|
||||
}
|
||||
siteURL, ok := serviceSettingsAsMap["SiteURL"]
|
||||
require.True(t, ok, "should've returned ServiceSettings.SiteURL")
|
||||
|
||||
siteURLAsBool, ok := siteURL.(bool)
|
||||
require.True(t, ok, "should've returned ServiceSettings.SiteURL as a boolean")
|
||||
require.True(t, siteURLAsBool, "should've returned ServiceSettings.SiteURL as true")
|
||||
|
||||
enableCustomEmoji, ok := serviceSettingsAsMap["EnableCustomEmoji"]
|
||||
require.True(t, ok, "should've returned ServiceSettings.EnableCustomEmoji")
|
||||
|
||||
enableCustomEmojiAsBool, ok := enableCustomEmoji.(bool)
|
||||
require.True(t, ok, "should've returned ServiceSettings.EnableCustomEmoji as a boolean")
|
||||
require.True(t, enableCustomEmojiAsBool, "should've returned ServiceSettings.EnableCustomEmoji as true")
|
||||
|
||||
_, ok = envConfig["TeamSettings"]
|
||||
require.False(t, ok, "should not have returned TeamSettings")
|
||||
})
|
||||
|
||||
t.Run("as team admin", func(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user