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)
|
require.NotEqual(t, "", cfg.TeamSettings.SiteName)
|
||||||
|
|
||||||
if *cfg.LdapSettings.BindPassword != model.FAKE_SETTING && len(*cfg.LdapSettings.BindPassword) != 0 {
|
if *cfg.LdapSettings.BindPassword != model.FAKE_SETTING && len(*cfg.LdapSettings.BindPassword) != 0 {
|
||||||
t.Fatal("did not sanitize properly")
|
require.FailNow(t, "did not sanitize properly")
|
||||||
}
|
|
||||||
if *cfg.FileSettings.PublicLinkSalt != model.FAKE_SETTING {
|
|
||||||
t.Fatal("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 {
|
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 {
|
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 {
|
if *cfg.GitLabSettings.Secret != model.FAKE_SETTING && len(*cfg.GitLabSettings.Secret) != 0 {
|
||||||
t.Fatal("did not sanitize properly")
|
require.FailNow(t, "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.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 {
|
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 {
|
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) {
|
t.Run("as system user", func(t *testing.T) {
|
||||||
ok, resp := Client.ReloadConfig()
|
ok, resp := Client.ReloadConfig()
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
if ok {
|
require.False(t, ok, "should not Reload the config due no permission.")
|
||||||
t.Fatal("should not Reload the config due no permission.")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("as system admin", func(t *testing.T) {
|
t.Run("as system admin", func(t *testing.T) {
|
||||||
ok, resp := th.SystemAdminClient.ReloadConfig()
|
ok, resp := th.SystemAdminClient.ReloadConfig()
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
if !ok {
|
require.True(t, ok, "should Reload the config")
|
||||||
t.Fatal("should Reload the config")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("as restricted system admin", func(t *testing.T) {
|
t.Run("as restricted system admin", func(t *testing.T) {
|
||||||
@@ -79,9 +70,7 @@ func TestReloadConfig(t *testing.T) {
|
|||||||
|
|
||||||
ok, resp := Client.ReloadConfig()
|
ok, resp := Client.ReloadConfig()
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
if ok {
|
require.False(t, ok, "should not Reload the config due no permission.")
|
||||||
t.Fatal("should not Reload the config due no permission.")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,31 +234,28 @@ func TestGetEnvironmentConfig(t *testing.T) {
|
|||||||
envConfig, resp := SystemAdminClient.GetEnvironmentConfig()
|
envConfig, resp := SystemAdminClient.GetEnvironmentConfig()
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
if serviceSettings, ok := envConfig["ServiceSettings"]; !ok {
|
serviceSettings, ok := envConfig["ServiceSettings"]
|
||||||
t.Fatal("should've returned ServiceSettings")
|
require.True(t, ok, "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")
|
|
||||||
}
|
|
||||||
|
|
||||||
if enableCustomEmoji, ok := serviceSettingsAsMap["EnableCustomEmoji"]; !ok {
|
serviceSettingsAsMap, ok := serviceSettings.(map[string]interface{})
|
||||||
t.Fatal("should've returned ServiceSettings.EnableCustomEmoji")
|
require.True(t, ok, "should've returned ServiceSettings as a map")
|
||||||
} 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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := envConfig["TeamSettings"]; ok {
|
siteURL, ok := serviceSettingsAsMap["SiteURL"]
|
||||||
t.Fatal("should not have returned TeamSettings")
|
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) {
|
t.Run("as team admin", func(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user