From 547f89368e3124f299f38f53b2051e4ed4586e4f Mon Sep 17 00:00:00 2001 From: Howard Zhong Date: Mon, 7 Oct 2024 20:21:42 +0000 Subject: [PATCH] precise func name, func comment, more thorough state reset for test cases --- broker/broker_test.go | 2 +- broker/token_utils_test.go | 2 +- cache/advertise_test.go | 6 +- cache/cache_api_test.go | 8 +-- client/fed_linux_test.go | 14 ++--- client/fed_test.go | 36 ++++++------ client/handle_http_test.go | 12 ++-- client/main_test.go | 2 +- cmd/fed_serve_cache_test.go | 4 +- cmd/fed_serve_test.go | 4 +- cmd/generate_keygen_test.go | 4 +- cmd/origin_reset_password_test.go | 2 +- cmd/plugin_test.go | 16 +++--- config/config.go | 6 +- director/advertise_test.go | 12 ++-- director/cache_ads_test.go | 4 +- director/director_test.go | 24 ++++---- director/discovery_test.go | 4 +- director/origin_api_test.go | 2 +- director/prom_query_test.go | 4 +- director/sort_test.go | 8 +-- director/stat_test.go | 6 +- fed_test_utils/fed.go | 2 +- launcher_utils/advertise_test.go | 6 +- launcher_utils/register_namespace_test.go | 2 +- local_cache/cache_linux_test.go | 8 +-- local_cache/cache_test.go | 20 +++---- lotman/lotman_test.go | 14 ++--- oauth2/oidc_client_test.go | 10 ++-- origin/origin_db_test.go | 16 +++--- origin/reg_status_test.go | 16 +++--- registry/client_commands_test.go | 12 ++-- registry/registry_db_test.go | 4 +- registry/registry_test.go | 12 ++-- registry/registry_ui_test.go | 32 +++++------ registry/registry_validation_test.go | 4 +- server_utils/origin_test.go | 40 +++++-------- server_utils/registry_test.go | 6 +- server_utils/server_utils.go | 4 +- web_ui/authentication_test.go | 26 ++++----- web_ui/engine_test.go | 2 +- web_ui/prometheus_test.go | 6 +- web_ui/ui_test.go | 4 +- web_ui/ui_unix_test.go | 2 +- xrootd/authorization_test.go | 40 ++++++------- xrootd/fed_test.go | 4 +- xrootd/origin_test.go | 12 ++-- xrootd/xrootd_config_test.go | 68 +++++++++++------------ 48 files changed, 274 insertions(+), 280 deletions(-) diff --git a/broker/broker_test.go b/broker/broker_test.go index 0ed34c415..cada222d0 100644 --- a/broker/broker_test.go +++ b/broker/broker_test.go @@ -76,7 +76,7 @@ func getHelloWorldHandler(t *testing.T) func(resp http.ResponseWriter, req *http func Setup(t *testing.T, ctx context.Context, egrp *errgroup.Group) { dirpath := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Logging.Level", "Debug") viper.Set("ConfigDir", filepath.Join(dirpath, "config")) config.InitConfig() diff --git a/broker/token_utils_test.go b/broker/token_utils_test.go index 90180a4da..b6fbd9d24 100644 --- a/broker/token_utils_test.go +++ b/broker/token_utils_test.go @@ -32,7 +32,7 @@ import ( ) func TestGetCacheHostnameFromToken(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", t.TempDir()) config.InitConfig() require.NoError(t, config.InitClient()) diff --git a/cache/advertise_test.go b/cache/advertise_test.go index e3d09de94..4660b6194 100644 --- a/cache/advertise_test.go +++ b/cache/advertise_test.go @@ -83,8 +83,8 @@ func TestFilterNsAdsForCache(t *testing.T) { expectedNumNS: 2, }, } - server_utils.Reset() - defer server_utils.Reset() + server_utils.ResetTestState() + defer server_utils.ResetTestState() nsAds := []server_structs.NamespaceAdV2{ { @@ -131,7 +131,7 @@ func TestFilterNsAdsForCache(t *testing.T) { if testInput.permittedNS != nil { viper.Set("Cache.PermittedNamespaces", testInput.permittedNS) } - defer server_utils.Reset() + defer server_utils.ResetTestState() cacheServer.SetFilters() err = cacheServer.GetNamespaceAdsFromDirector() diff --git a/cache/cache_api_test.go b/cache/cache_api_test.go index fac082ccd..22694622f 100644 --- a/cache/cache_api_test.go +++ b/cache/cache_api_test.go @@ -33,13 +33,13 @@ import ( func TestCheckCacheSentinelLocation(t *testing.T) { t.Run("sentinel-not-set", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() err := CheckCacheSentinelLocation() assert.NoError(t, err) }) t.Run("sentinel-contains-dir", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set(param.Cache_SentinelLocation.GetName(), "/test.txt") err := CheckCacheSentinelLocation() require.Error(t, err) @@ -48,7 +48,7 @@ func TestCheckCacheSentinelLocation(t *testing.T) { t.Run("sentinel-dne", func(t *testing.T) { tmpDir := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set(param.Cache_SentinelLocation.GetName(), "test.txt") viper.Set(param.Cache_LocalRoot.GetName(), tmpDir) err := CheckCacheSentinelLocation() @@ -58,7 +58,7 @@ func TestCheckCacheSentinelLocation(t *testing.T) { t.Run("sentinel-exists", func(t *testing.T) { tmpDir := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set(param.Cache_SentinelLocation.GetName(), "test.txt") viper.Set(param.Cache_LocalRoot.GetName(), tmpDir) diff --git a/client/fed_linux_test.go b/client/fed_linux_test.go index 6ec18c4e4..468b40ef6 100644 --- a/client/fed_linux_test.go +++ b/client/fed_linux_test.go @@ -47,7 +47,7 @@ import ( func TestRecursiveUploadsAndDownloads(t *testing.T) { // Create instance of test federation - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, mixedAuthOriginCfg) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) @@ -221,7 +221,7 @@ func TestRecursiveUploadsAndDownloads(t *testing.T) { log.Errorln("Failure when shutting down transfer engine:", err) } // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) } @@ -242,7 +242,7 @@ func verifySuccessfulTransfer(t *testing.T, transferResults []client.TransferRes // Test that recursive uploads and downloads work with the ?recursive query func TestRecursiveUploadsAndDownloadsWithQuery(t *testing.T) { // Create instance of test federation - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, mixedAuthOriginCfg) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) @@ -256,7 +256,7 @@ func TestRecursiveUploadsAndDownloadsWithQuery(t *testing.T) { log.Errorln("Failure when shutting down transfer engine:", err) } // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) @@ -434,7 +434,7 @@ func TestRecursiveUploadsAndDownloadsWithQuery(t *testing.T) { // This tests that is origins disable listings, we should fail the download // Note: origins disabling listings override the existence of dirlisthost, causing a failure func TestFailureOnOriginDisablingListings(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Logging.Level", "debug") viper.Set("Origin.StorageType", "posix") @@ -458,7 +458,7 @@ func TestFailureOnOriginDisablingListings(t *testing.T) { func TestSyncUpload(t *testing.T) { // Create instance of test federation - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, bothAuthOriginCfg) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) @@ -588,7 +588,7 @@ func TestSyncUpload(t *testing.T) { func TestSyncDownload(t *testing.T) { // Create instance of test federation - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, bothAuthOriginCfg) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) diff --git a/client/fed_test.go b/client/fed_test.go index 8cfd02ffd..83c0faa93 100644 --- a/client/fed_test.go +++ b/client/fed_test.go @@ -105,7 +105,7 @@ func getTempToken(t *testing.T) (tempToken *os.File, tkn string) { // A test that spins up a federation, and tests object get and put func TestGetAndPutAuth(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, bothAuthOriginCfg) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) @@ -283,13 +283,13 @@ func TestGetAndPutAuth(t *testing.T) { }) t.Cleanup(func() { // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) } // A test that spins up a federation, and tests object get and put func TestCopyAuth(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, bothAuthOriginCfg) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) @@ -444,13 +444,13 @@ func TestCopyAuth(t *testing.T) { log.Errorln("Failure when shutting down transfer engine:", err) } // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) } // A test that spins up the federation, where the origin is in EnablePublicReads mode. Then GET a file from the origin without a token func TestGetPublicRead(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, bothPublicOriginCfg) @@ -481,15 +481,15 @@ func TestGetPublicRead(t *testing.T) { }) t.Cleanup(func() { // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) } // A test that spins up a federation, and tests object stat func TestObjectStat(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, mixedAuthOriginCfg) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) require.NoError(t, err) @@ -592,9 +592,9 @@ func TestObjectStat(t *testing.T) { // Test the functionality of the direct reads feature (?directread) func TestDirectReads(t *testing.T) { - defer server_utils.Reset() + defer server_utils.ResetTestState() t.Run("testDirectReadsSuccess", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Origin.EnableDirectReads", true) fed := fed_test_utils.NewFedTest(t, bothPublicOriginCfg) @@ -636,7 +636,7 @@ func TestDirectReads(t *testing.T) { // Test that direct reads fail if DirectReads=false is set for origin config but true for namespace/export t.Run("testDirectReadsDirectReadFalseByOrigin", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, pubOriginNoDirectRead) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) @@ -666,7 +666,7 @@ func TestDirectReads(t *testing.T) { // Test that direct reads fail if DirectReads=false is set for namespace/export config but true for origin t.Run("testDirectReadsDirectReadFalseByNamespace", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, pubExportNoDirectRead) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) @@ -698,8 +698,8 @@ func TestDirectReads(t *testing.T) { // Test the functionality of NewTransferJob, checking we return at the correct locations for certain errors func TestNewTransferJob(t *testing.T) { - server_utils.Reset() - defer server_utils.Reset() + server_utils.ResetTestState() + defer server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, mixedAuthOriginCfg) discoveryUrl, err := url.Parse(param.Federation_DiscoveryUrl.GetString()) @@ -746,9 +746,9 @@ func TestNewTransferJob(t *testing.T) { // A test that spins up a federation, and tests object list func TestObjectList(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, mixedAuthOriginCfg) // Other set-up items: @@ -878,7 +878,7 @@ func TestObjectList405Error(t *testing.T) { // Startup a mini-federation and ensure the "pack=auto" functionality works // end-to-end func TestClientUnpack(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() err := config.InitClient() require.NoError(t, err) @@ -937,7 +937,7 @@ func TestClientUnpack(t *testing.T) { // A test that generates a token locally from the private key func TestTokenGenerate(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() fed := fed_test_utils.NewFedTest(t, bothAuthOriginCfg) diff --git a/client/handle_http_test.go b/client/handle_http_test.go index 52ab52d8a..a1ec2c307 100644 --- a/client/handle_http_test.go +++ b/client/handle_http_test.go @@ -48,7 +48,7 @@ import ( ) func TestMain(m *testing.M) { - server_utils.Reset() + server_utils.ResetTestState() if err := config.InitClient(); err != nil { os.Exit(1) } @@ -146,7 +146,7 @@ func TestNewTransferDetailsEnv(t *testing.T) { assert.Equal(t, "https", transfers[0].Url.Scheme) assert.Equal(t, false, transfers[0].Proxy) os.Unsetenv("OSG_DISABLE_PROXY_FALLBACK") - server_utils.Reset() + server_utils.ResetTestState() err := config.InitClient() assert.Nil(t, err) } @@ -509,7 +509,7 @@ func TestTimeoutHeaderSetForDownload(t *testing.T) { assert.NoError(t, err) _, _, _, _, err = downloadHTTP(ctx, nil, nil, transferAttemptDetails{Url: serverURL, Proxy: false}, filepath.Join(t.TempDir(), "test.txt"), -1, "", "") assert.NoError(t, err) - server_utils.Reset() + server_utils.ResetTestState() } func TestJobIdHeaderSetForDownload(t *testing.T) { @@ -548,7 +548,7 @@ func TestJobIdHeaderSetForDownload(t *testing.T) { assert.NoError(t, err) _, _, _, _, err = downloadHTTP(ctx, nil, nil, transferAttemptDetails{Url: serverURL, Proxy: false}, filepath.Join(t.TempDir(), "test.txt"), -1, "", "") assert.NoError(t, err) - server_utils.Reset() + server_utils.ResetTestState() os.Unsetenv("_CONDOR_JOB_AD") } @@ -911,8 +911,8 @@ func TestFailedLargeUploadError(t *testing.T) { } func TestNewTransferEngine(t *testing.T) { - server_utils.Reset() - defer server_utils.Reset() + server_utils.ResetTestState() + defer server_utils.ResetTestState() // Test we fail if we do not call initclient() before t.Run("TestInitClientNotCalled", func(t *testing.T) { config.ResetClientInitialized() diff --git a/client/main_test.go b/client/main_test.go index efc6ab788..daacc05a7 100644 --- a/client/main_test.go +++ b/client/main_test.go @@ -139,7 +139,7 @@ func TestGetToken(t *testing.T) { // Need a namespace for token acquisition defer os.Unsetenv("PELICAN_FEDERATION_TOPOLOGYNAMESPACEURL") os.Setenv("PELICAN_TOPOLOGY_NAMESPACE_URL", "https://topology.opensciencegrid.org/osdf/namespaces") - server_utils.Reset() + server_utils.ResetTestState() err := config.InitClient() assert.Nil(t, err) diff --git a/cmd/fed_serve_cache_test.go b/cmd/fed_serve_cache_test.go index b4436d9ac..abe45ed7b 100644 --- a/cmd/fed_serve_cache_test.go +++ b/cmd/fed_serve_cache_test.go @@ -44,9 +44,9 @@ func TestFedServeCache(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() modules := server_structs.ServerType(0) modules.Set(server_structs.CacheType) diff --git a/cmd/fed_serve_test.go b/cmd/fed_serve_test.go index a9283f1ae..a5f39c646 100644 --- a/cmd/fed_serve_test.go +++ b/cmd/fed_serve_test.go @@ -47,9 +47,9 @@ func TestFedServePosixOrigin(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() modules := server_structs.ServerType(0) modules.Set(server_structs.OriginType) diff --git a/cmd/generate_keygen_test.go b/cmd/generate_keygen_test.go index 868c7f886..3eb111509 100644 --- a/cmd/generate_keygen_test.go +++ b/cmd/generate_keygen_test.go @@ -44,7 +44,7 @@ func setupTestRun(t *testing.T) string { t.Cleanup(func() { err := os.Chdir(wd) require.NoError(t, err) - server_utils.Reset() + server_utils.ResetTestState() config.ResetIssuerJWKPtr() }) return tmpDir @@ -67,7 +67,7 @@ func TestKeygenMain(t *testing.T) { config.ResetIssuerJWKPtr() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() config.ResetIssuerJWKPtr() }) diff --git a/cmd/origin_reset_password_test.go b/cmd/origin_reset_password_test.go index 545604ab2..07db18808 100644 --- a/cmd/origin_reset_password_test.go +++ b/cmd/origin_reset_password_test.go @@ -43,7 +43,7 @@ func TestResetPassword(t *testing.T) { defer cancel() dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", dirName) config.InitConfig() viper.Set("Server.WebPort", 8444) diff --git a/cmd/plugin_test.go b/cmd/plugin_test.go index 9cc50e5ce..582f0c0f4 100644 --- a/cmd/plugin_test.go +++ b/cmd/plugin_test.go @@ -232,12 +232,12 @@ func (f *FedTest) Teardown() { f.Cancel() f.FedCancel() assert.NoError(f.T, f.ErrGroup.Wait()) - server_utils.Reset() + server_utils.ResetTestState() } // Test the main function for the pelican plugin func TestStashPluginMain(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() oldPrefix, err := config.SetPreferredPrefix(config.StashPrefix) defer func() { @@ -313,7 +313,7 @@ func TestStashPluginMain(t *testing.T) { // Test multiple downloads from the plugin func TestPluginMulti(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() dirName := t.TempDir() @@ -377,8 +377,8 @@ func TestPluginMulti(t *testing.T) { // Test multiple downloads from the plugin func TestPluginDirectRead(t *testing.T) { - server_utils.Reset() - defer server_utils.Reset() + server_utils.ResetTestState() + defer server_utils.ResetTestState() dirName := t.TempDir() @@ -453,7 +453,7 @@ func TestPluginDirectRead(t *testing.T) { func TestPluginCorrectStartAndEndTime(t *testing.T) { test_utils.InitClient(t, nil) server_utils.ResetOriginExports() - defer server_utils.Reset() + defer server_utils.ResetTestState() // Set up our http backend so that we can sleep during transfer body := "Hello, World!" @@ -665,8 +665,8 @@ func TestFailTransfer(t *testing.T) { // Test recursive downloads from the plugin func TestPluginRecursiveDownload(t *testing.T) { - server_utils.Reset() - defer server_utils.Reset() + server_utils.ResetTestState() + defer server_utils.ResetTestState() dirName := t.TempDir() diff --git a/config/config.go b/config/config.go index 3660b13d4..e12075851 100644 --- a/config/config.go +++ b/config/config.go @@ -1504,6 +1504,7 @@ func InitClient() error { return nil } +// This function resets most states for test cases, including 1. viper settings, 2. preferred prefix, 3. transport object, 4. Federation metadata back to their default func ResetConfig() { viper.Reset() @@ -1519,5 +1520,8 @@ func ResetConfig() { globalFedInfo = pelican_url.FederationDiscovery{} globalFedErr = nil - // deleting Origin exports is done by Reset() in server_utils pkg + ResetIssuerJWKPtr() + ResetClientInitialized() + + // other than what's above, resetting Origin exports will be done by ResetTestState() in server_utils pkg } diff --git a/director/advertise_test.go b/director/advertise_test.go index de7386997..4b4e0784f 100644 --- a/director/advertise_test.go +++ b/director/advertise_test.go @@ -200,10 +200,10 @@ func multiExportsTopoJSONHandler(w http.ResponseWriter, r *http.Request) { func TestAdvertiseOSDF(t *testing.T) { t.Run("mock-topology-parse-correctly", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() serverAds.DeleteAll() defer func() { - server_utils.Reset() + server_utils.ResetTestState() serverAds.DeleteAll() }() @@ -252,10 +252,10 @@ func TestAdvertiseOSDF(t *testing.T) { }) t.Run("multiple-ns-single-origin", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() serverAds.DeleteAll() defer func() { - server_utils.Reset() + server_utils.ResetTestState() serverAds.DeleteAll() }() @@ -280,10 +280,10 @@ func TestAdvertiseOSDF(t *testing.T) { }) t.Run("caches-serving-multiple-nss", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() serverAds.DeleteAll() defer func() { - server_utils.Reset() + server_utils.ResetTestState() serverAds.DeleteAll() }() diff --git a/director/cache_ads_test.go b/director/cache_ads_test.go index 643433527..15699834c 100644 --- a/director/cache_ads_test.go +++ b/director/cache_ads_test.go @@ -432,7 +432,7 @@ func TestRecordAd(t *testing.T) { t.Run("recorded-sad-should-match-health-test-utils-one", func(t *testing.T) { t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() healthTestUtilsMutex.Lock() statUtilsMutex.Lock() defer statUtilsMutex.Unlock() @@ -443,7 +443,7 @@ func TestRecordAd(t *testing.T) { serverAds.DeleteAll() geoIPOverrides = nil }) - server_utils.Reset() + server_utils.ResetTestState() func() { geoIPOverrides = nil diff --git a/director/director_test.go b/director/director_test.go index 808af301b..adc00de0d 100644 --- a/director/director_test.go +++ b/director/director_test.go @@ -141,7 +141,7 @@ func TestDirectorRegistration(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() // Mock registry server ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { @@ -1077,7 +1077,7 @@ func TestDiscoverOriginCache(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() // Direcor SD will only be used for director's Prometheus scraper to get available origins, // so the token issuer is issentially the director server itself // There's no need to rely on Federation.DirectorUrl as token issuer in this case @@ -1369,7 +1369,7 @@ func TestRedirects(t *testing.T) { expectedPath = "/api/v1.0/director/object/foo/bar" assert.Equal(t, expectedPath, c.Request.URL.Path) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("redirect-middleware", func(t *testing.T) { @@ -1459,7 +1459,7 @@ func TestRedirects(t *testing.T) { expectedPath = "/api/v1.0/director/origin/foo/bar" assert.Equal(t, expectedPath, c.Request.URL.Path) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("cache-test-file-redirect", func(t *testing.T) { @@ -1476,9 +1476,9 @@ func TestRedirects(t *testing.T) { }) t.Run("redirect-link-header-length", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() }) viper.Set("Director.CacheSortMethod", "random") @@ -1511,9 +1511,9 @@ func TestRedirects(t *testing.T) { // Make sure collections-url is correctly populated when the ns/origin comes from topology t.Run("collections-url-from-topology", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() }) viper.Set("Director.CacheSortMethod", "random") @@ -1538,9 +1538,9 @@ func TestRedirects(t *testing.T) { }) t.Run("object-endpoint-returns-all-headers", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() }) viper.Set("Director.CacheSortMethod", "random") @@ -1561,9 +1561,9 @@ func TestRedirects(t *testing.T) { }) t.Run("origin-endpoint-returns-all-headers", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() }) viper.Set("Director.CacheSortMethod", "random") diff --git a/director/discovery_test.go b/director/discovery_test.go index 9c24a225a..013b87270 100644 --- a/director/discovery_test.go +++ b/director/discovery_test.go @@ -139,7 +139,7 @@ func TestFederationDiscoveryHandler(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", t.TempDir()) viper.Set("Federation.DirectorUrl", tc.dirUrl) viper.Set("Federation.RegistryUrl", tc.regUrl) @@ -212,7 +212,7 @@ func TestOidcDiscoveryHandler(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", t.TempDir()) viper.Set("Federation.DirectorUrl", tc.dirUrl) config.InitConfig() diff --git a/director/origin_api_test.go b/director/origin_api_test.go index 53b2ea0a6..1c3c350d7 100644 --- a/director/origin_api_test.go +++ b/director/origin_api_test.go @@ -47,7 +47,7 @@ func TestVerifyAdvertiseToken(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() tDir := t.TempDir() kfile := filepath.Join(tDir, "t-key") diff --git a/director/prom_query_test.go b/director/prom_query_test.go index c2f3df445..9cb26654d 100644 --- a/director/prom_query_test.go +++ b/director/prom_query_test.go @@ -203,8 +203,8 @@ func TestParsePromRes(t *testing.T) { } func TestQueryPrometheus(t *testing.T) { - server_utils.Reset() - t.Cleanup(server_utils.Reset) + server_utils.ResetTestState() + t.Cleanup(server_utils.ResetTestState) handler := func(w http.ResponseWriter, r *http.Request) { query := r.URL.Query().Get("query") diff --git a/director/sort_test.go b/director/sort_test.go index 7a2b1cc44..9a82f7a5f 100644 --- a/director/sort_test.go +++ b/director/sort_test.go @@ -45,9 +45,9 @@ import ( var yamlMockup string func TestCheckOverrides(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() geoIPOverrides = nil }) @@ -192,9 +192,9 @@ func TestSortServerAdsByTopo(t *testing.T) { } func TestSortServerAds(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() geoIPOverrides = nil }) diff --git a/director/stat_test.go b/director/stat_test.go index 1015905e4..7f74755c5 100644 --- a/director/stat_test.go +++ b/director/stat_test.go @@ -41,7 +41,7 @@ import ( ) func TestQueryServersForObject(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Director.MinStatResponse", 1) viper.Set("Director.MaxStatResponse", 1) viper.Set("Director.StatTimeout", time.Microsecond*200) @@ -217,7 +217,7 @@ func TestQueryServersForObject(t *testing.T) { cleanupMock() // Restore the old serverAds at the end of this test func serverAds = oldAds - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("empty-server-ads-returns", func(t *testing.T) { @@ -699,7 +699,7 @@ func TestQueryServersForObject(t *testing.T) { } func TestSendHeadReq(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() // Start a local HTTP server server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { diff --git a/fed_test_utils/fed.go b/fed_test_utils/fed.go index 9eaa67f61..2dc26416b 100644 --- a/fed_test_utils/fed.go +++ b/fed_test_utils/fed.go @@ -226,7 +226,7 @@ func NewFedTest(t *testing.T, originConfig string) (ft *FedTest) { err := os.RemoveAll(tmpPath) require.NoError(t, err) // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) return diff --git a/launcher_utils/advertise_test.go b/launcher_utils/advertise_test.go index 99aaff019..0b1b304ca 100644 --- a/launcher_utils/advertise_test.go +++ b/launcher_utils/advertise_test.go @@ -37,7 +37,7 @@ import ( func TestGetSitenameFromReg(t *testing.T) { t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("no-registry-url", func(t *testing.T) { @@ -50,7 +50,7 @@ func TestGetSitenameFromReg(t *testing.T) { }) t.Run("registry-returns-404", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { w.WriteHeader(http.StatusNotFound) })) @@ -64,7 +64,7 @@ func TestGetSitenameFromReg(t *testing.T) { }) t.Run("registry-returns-correct-object", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { if strings.HasPrefix(req.URL.Path, "/api/v1.0/registry") { prefix := strings.TrimPrefix(req.URL.Path, "/api/v1.0/registry") diff --git a/launcher_utils/register_namespace_test.go b/launcher_utils/register_namespace_test.go index 657b51da3..f6e273b63 100644 --- a/launcher_utils/register_namespace_test.go +++ b/launcher_utils/register_namespace_test.go @@ -57,7 +57,7 @@ func TestRegistration(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", tempConfigDir) config.InitConfig() diff --git a/local_cache/cache_linux_test.go b/local_cache/cache_linux_test.go index 5785e45f5..8f85ad68d 100644 --- a/local_cache/cache_linux_test.go +++ b/local_cache/cache_linux_test.go @@ -52,7 +52,7 @@ import ( func TestPurge(t *testing.T) { tmpDir := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("LocalCache.Size", "5MB") ft := fed_test_utils.NewFedTest(t, pubOriginCfg) @@ -105,7 +105,7 @@ func TestPurge(t *testing.T) { log.Errorln("Failure when shutting down transfer engine:", err) } // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) } @@ -114,7 +114,7 @@ func TestPurge(t *testing.T) { func TestForcePurge(t *testing.T) { tmpDir := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("LocalCache.Size", "5MB") // Decrease the low water mark so invoking purge will result in 3 files in the cache. viper.Set("LocalCache.LowWaterMarkPercentage", "80") @@ -197,6 +197,6 @@ func TestForcePurge(t *testing.T) { log.Errorln("Failure when shutting down transfer engine:", err) } // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) } diff --git a/local_cache/cache_test.go b/local_cache/cache_test.go index 963607957..8401a4bd9 100644 --- a/local_cache/cache_test.go +++ b/local_cache/cache_test.go @@ -65,7 +65,7 @@ var ( // The download is done twice -- once to verify functionality and once // as a cache hit. func TestFedPublicGet(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ft := fed_test_utils.NewFedTest(t, pubOriginCfg) lc, err := local_cache.NewLocalCache(ft.Ctx, ft.Egrp) @@ -90,7 +90,7 @@ func TestFedPublicGet(t *testing.T) { // Test the local cache library on an authenticated GET. func TestFedAuthGet(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ft := fed_test_utils.NewFedTest(t, authOriginCfg) lc, err := local_cache.NewLocalCache(ft.Ctx, ft.Egrp) @@ -122,7 +122,7 @@ func TestFedAuthGet(t *testing.T) { // Test a raw HTTP request (no Pelican client) works with the local cache func TestHttpReq(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ft := fed_test_utils.NewFedTest(t, authOriginCfg) transport := config.GetTransport().Clone() @@ -145,7 +145,7 @@ func TestHttpReq(t *testing.T) { // Test a raw HTTP request (no Pelican client) returns a 404 for an unknown object func TestHttpFailures(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() fed_test_utils.NewFedTest(t, authOriginCfg) transport := config.GetTransport().Clone() @@ -189,7 +189,7 @@ func TestHttpFailures(t *testing.T) { // Test that the client library (with authentication) works with the local cache func TestClient(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ft := fed_test_utils.NewFedTest(t, authOriginCfg) ctx, cancel, egrp := test_utils.TestContext(context.Background(), t) @@ -339,13 +339,13 @@ func TestClient(t *testing.T) { require.NoError(t, err) } // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) } // Test that HEAD requests to the local cache return the correct result func TestStat(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ft := fed_test_utils.NewFedTest(t, pubOriginCfg) lc, err := local_cache.NewLocalCache(ft.Ctx, ft.Egrp) @@ -372,7 +372,7 @@ func TestStat(t *testing.T) { func TestLargeFile(t *testing.T) { tmpDir := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Client.MaximumDownloadSpeed", 40*1024*1024) ft := fed_test_utils.NewFedTest(t, pubOriginCfg) @@ -406,7 +406,7 @@ func TestLargeFile(t *testing.T) { log.Errorln("Failure when shutting down transfer engine:", err) } // Throw in a config.Reset for good measure. Keeps our env squeaky clean! - server_utils.Reset() + server_utils.ResetTestState() }) } @@ -416,7 +416,7 @@ func TestLargeFile(t *testing.T) { func TestOriginUnresponsive(t *testing.T) { tmpDir := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Transport.ResponseHeaderTimeout", "3s") viper.Set("Logging.Level", "debug") ft := fed_test_utils.NewFedTest(t, pubOriginCfg) diff --git a/lotman/lotman_test.go b/lotman/lotman_test.go index 5b3dfd132..61975f6b1 100644 --- a/lotman/lotman_test.go +++ b/lotman/lotman_test.go @@ -59,13 +59,13 @@ func setupLotmanFromConf(t *testing.T, readConfig bool, name string) (bool, func success := InitLotman() //reset func return success, func() { - server_utils.Reset() + server_utils.ResetTestState() } } // Test the library initializer. NOTE: this also tests CreateLot, which is a part of initialization. func TestLotmanInit(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Run("TestBadInit", func(t *testing.T) { // We haven't set various bits needed to create the lots, like discovery URL @@ -119,7 +119,7 @@ func TestLotmanInit(t *testing.T) { } func TestLotmanInitFromConfig(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() success, cleanup := setupLotmanFromConf(t, true, "LotmanInitConf") defer cleanup() @@ -219,7 +219,7 @@ func TestGetLotmanLib(t *testing.T) { } func TestGetAuthzCallers(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() success, cleanup := setupLotmanFromConf(t, true, "LotmanGetAuthzCalleres") defer cleanup() require.True(t, success) @@ -238,7 +238,7 @@ func TestGetAuthzCallers(t *testing.T) { } func TestGetLot(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() success, cleanup := setupLotmanFromConf(t, true, "LotmanGetLot") defer cleanup() require.True(t, success) @@ -261,7 +261,7 @@ func TestGetLot(t *testing.T) { } func TestUpdateLot(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() success, cleanup := setupLotmanFromConf(t, true, "LotmanInitConf") defer cleanup() require.True(t, success) @@ -299,7 +299,7 @@ func TestUpdateLot(t *testing.T) { } func TestDeleteLotsRec(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() success, cleanup := setupLotmanFromConf(t, true, "LotmanInitConf") defer cleanup() require.True(t, success) diff --git a/oauth2/oidc_client_test.go b/oauth2/oidc_client_test.go index b7aabcd7a..6b7fc7305 100644 --- a/oauth2/oidc_client_test.go +++ b/oauth2/oidc_client_test.go @@ -30,12 +30,12 @@ import ( ) func TestGetRedirectURL(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("no-redirect-host-no-cb-path-set", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set(param.Server_ExternalWebUrl.GetName(), "https://localhost:8888") get, err := GetRedirectURL("") require.NoError(t, err) @@ -43,7 +43,7 @@ func TestGetRedirectURL(t *testing.T) { }) t.Run("no-redirect-host-cp-path-set", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set(param.Server_ExternalWebUrl.GetName(), "https://localhost:8888") get, err := GetRedirectURL("/new/url") require.NoError(t, err) @@ -51,7 +51,7 @@ func TestGetRedirectURL(t *testing.T) { }) t.Run("redirect-host-cp-path-set", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set(param.Server_ExternalWebUrl.GetName(), "https://ea123fsac:8888") viper.Set("Server.WebPort", 8888) viper.Set(param.OIDC_ClientRedirectHostname.GetName(), "localhost") diff --git a/origin/origin_db_test.go b/origin/origin_db_test.go index 09ec2089e..2e2a4d19f 100644 --- a/origin/origin_db_test.go +++ b/origin/origin_db_test.go @@ -132,10 +132,10 @@ func TestCollectionExistsByUUID(t *testing.T) { } func TestGetCollectionByUUID(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() setupMockOriginDB(t) t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() teardownMockOriginDB(t) }) err := insertMockDBData(mockGC) @@ -165,10 +165,10 @@ func TestGetCollectionByUUID(t *testing.T) { } func TestCreateCollection(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() setupMockOriginDB(t) t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() teardownMockOriginDB(t) }) @@ -205,10 +205,10 @@ func TestCreateCollection(t *testing.T) { } func TestUpdateCollection(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() setupMockOriginDB(t) t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() teardownMockOriginDB(t) }) @@ -235,10 +235,10 @@ func TestUpdateCollection(t *testing.T) { } func TestDeleteCollectionByUUID(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() setupMockOriginDB(t) t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() teardownMockOriginDB(t) }) diff --git a/origin/reg_status_test.go b/origin/reg_status_test.go index bbe47987a..2fb65c888 100644 --- a/origin/reg_status_test.go +++ b/origin/reg_status_test.go @@ -73,14 +73,14 @@ func mockRegistryCheck(t *testing.T) *httptest.Server { func TestFetchRegStatus(t *testing.T) { t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() }) t.Run("successful-fetch", func(t *testing.T) { ts := mockRegistryCheck(t) defer ts.Close() - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() config.SetFederation(pelican_url.FederationDiscovery{ RegistryEndpoint: ts.URL, @@ -104,7 +104,7 @@ func TestFetchRegStatus(t *testing.T) { w.WriteHeader(http.StatusNotFound) })) defer ts.Close() - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() config.SetFederation(pelican_url.FederationDiscovery{ RegistryEndpoint: ts.URL, @@ -124,7 +124,7 @@ func TestFetchRegStatus(t *testing.T) { w.WriteHeader(http.StatusInternalServerError) })) defer ts.Close() - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() config.SetFederation(pelican_url.FederationDiscovery{ RegistryEndpoint: ts.URL, @@ -138,11 +138,11 @@ func TestFetchRegStatus(t *testing.T) { func TestWrapExportsByStatus(t *testing.T) { t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() }) - server_utils.Reset() + server_utils.ResetTestState() config.SetFederation(pelican_url.FederationDiscovery{ RegistryEndpoint: "https://mock-registry.org", }) @@ -190,7 +190,7 @@ func TestWrapExportsByStatus(t *testing.T) { }) t.Run("partial-cached", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ts := mockRegistryCheck(t) defer ts.Close() config.ResetFederationForTest() @@ -236,6 +236,6 @@ func TestWrapExportsByStatus(t *testing.T) { assert.EqualValues(t, expected, got) registrationsStatus.DeleteAll() - server_utils.Reset() + server_utils.ResetTestState() }) } diff --git a/registry/client_commands_test.go b/registry/client_commands_test.go index 98ecfb431..400e9eb8d 100644 --- a/registry/client_commands_test.go +++ b/registry/client_commands_test.go @@ -72,7 +72,7 @@ func TestServeNamespaceRegistry(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() svr := registryMockup(ctx, t, "serveregistry") defer func() { @@ -141,7 +141,7 @@ func TestServeNamespaceRegistry(t *testing.T) { stdoutCapture = string(capturedOutput[:n]) assert.Equal(t, "[]\n", stdoutCapture) }) - server_utils.Reset() + server_utils.ResetTestState() } func TestRegistryKeyChainingOSDF(t *testing.T) { @@ -149,7 +149,7 @@ func TestRegistryKeyChainingOSDF(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() _, err := config.SetPreferredPrefix(config.OsdfPrefix) assert.NoError(t, err) viper.Set("Federation.DirectorUrl", "https://osdf-director.osg-htc.org") @@ -239,7 +239,7 @@ func TestRegistryKeyChainingOSDF(t *testing.T) { _, err = config.SetPreferredPrefix(config.PelicanPrefix) assert.NoError(t, err) - server_utils.Reset() + server_utils.ResetTestState() } func TestRegistryKeyChaining(t *testing.T) { @@ -247,7 +247,7 @@ func TestRegistryKeyChaining(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() // On by default, but just to make things explicit viper.Set("Registry.RequireKeyChaining", true) @@ -298,5 +298,5 @@ func TestRegistryKeyChaining(t *testing.T) { err = NamespaceRegister(privKey, registrySvr.URL+"/api/v1.0/registry", "", "/foo", "") require.NoError(t, err) - server_utils.Reset() + server_utils.ResetTestState() } diff --git a/registry/registry_db_test.go b/registry/registry_db_test.go index f25bc061f..402887f0e 100644 --- a/registry/registry_db_test.go +++ b/registry/registry_db_test.go @@ -806,7 +806,7 @@ func topologyMockup(t *testing.T, namespaces []string) *httptest.Server { } func TestRegistryTopology(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() topoNamespaces := []string{"/topo/foo", "/topo/bar"} svr := topologyMockup(t, topoNamespaces) @@ -895,7 +895,7 @@ func TestRegistryTopology(t *testing.T) { require.NoError(t, err) require.False(t, exists) - server_utils.Reset() + server_utils.ResetTestState() } func TestGetTopoPrefixString(t *testing.T) { diff --git a/registry/registry_test.go b/registry/registry_test.go index b94c0fb59..43ad3d7e0 100644 --- a/registry/registry_test.go +++ b/registry/registry_test.go @@ -82,7 +82,7 @@ func TestHandleWildcard(t *testing.T) { }) t.Run("match-wildcard-metadataHandler", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() mockPrefix := "/testnamespace/foo" setupMockRegistryDB(t) @@ -152,7 +152,7 @@ func TestHandleWildcard(t *testing.T) { for _, tc := range mockApprovalTcs { t.Run(tc.Name, func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Registry.RequireCacheApproval", tc.CacheApprovedOnly) viper.Set("Registry.RequireOriginApproval", tc.OriginApprovedOnly) @@ -198,7 +198,7 @@ func TestCheckNamespaceCompleteHandler(t *testing.T) { router.POST("/namespaces/check/status", checkStatusHandler) t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() }) @@ -254,7 +254,7 @@ func TestCheckNamespaceCompleteHandler(t *testing.T) { t.Run("incomplete-registration", func(t *testing.T) { resetNamespaceDB(t) - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() config.SetFederation(pelican_url.FederationDiscovery{ RegistryEndpoint: "https://registry.org", @@ -292,7 +292,7 @@ func TestCheckNamespaceCompleteHandler(t *testing.T) { t.Run("complete-registration", func(t *testing.T) { resetNamespaceDB(t) - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() config.SetFederation(pelican_url.FederationDiscovery{ RegistryEndpoint: "https://registry.org", @@ -338,7 +338,7 @@ func TestCheckNamespaceCompleteHandler(t *testing.T) { t.Run("multiple-complete-registrations", func(t *testing.T) { resetNamespaceDB(t) - server_utils.Reset() + server_utils.ResetTestState() config.ResetFederationForTest() config.SetFederation(pelican_url.FederationDiscovery{ RegistryEndpoint: "https://registry.org", diff --git a/registry/registry_ui_test.go b/registry/registry_ui_test.go index a469e86dc..d680b9210 100644 --- a/registry/registry_ui_test.go +++ b/registry/registry_ui_test.go @@ -57,7 +57,7 @@ func mockAdminToken() (string, error) { } func TestListNamespaces(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() ctx, cancel, egrp := test_utils.TestContext(context.Background(), t) defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() @@ -311,7 +311,7 @@ func TestListNamespaces(t *testing.T) { } func TestListNamespacesForUser(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() _, cancel, egrp := test_utils.TestContext(context.Background(), t) defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() @@ -721,10 +721,10 @@ func TestUpdateNamespaceStatus(t *testing.T) { } func TestCreateNamespace(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() customRegFieldsConfigs = []customRegFieldsConfig{} }) @@ -806,7 +806,7 @@ func TestCreateNamespace(t *testing.T) { }) t.Run("missing-institution-returns-400", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Registry.Institutions", []map[string]string{{"name": "Mock School", "id": "123"}}) resetNamespaceDB(t) jwks, err := test_utils.GenerateJWKS() @@ -826,7 +826,7 @@ func TestCreateNamespace(t *testing.T) { require.NoError(t, err) assert.Equal(t, http.StatusBadRequest, w.Result().StatusCode) assert.Contains(t, string(body), "Validation for Institution failed:") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("invalid-prefix-returns-400", func(t *testing.T) { @@ -915,7 +915,7 @@ func TestCreateNamespace(t *testing.T) { }) t.Run("key-chaining-failure-returns-400", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Registry.RequireKeyChaining", true) resetNamespaceDB(t) @@ -942,7 +942,7 @@ func TestCreateNamespace(t *testing.T) { require.NoError(t, err) assert.Equal(t, http.StatusBadRequest, w.Result().StatusCode) assert.Contains(t, string(body), "Cannot register a namespace that is suffixed or prefixed by an already-registered namespace unless the incoming public key matches a registered key") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("inst-failure-returns-400", func(t *testing.T) { @@ -1095,7 +1095,7 @@ func TestCreateNamespace(t *testing.T) { assert.Equal(t, "admin", nss[0].AdminMetadata.UserID) assert.Equal(t, server_structs.RegPending, nss[0].AdminMetadata.Status) assert.NotEqual(t, time.Time{}, nss[0].AdminMetadata.CreatedAt) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("osdf-topology-same-prefix-request-gives-200", func(t *testing.T) { @@ -1137,14 +1137,14 @@ func TestCreateNamespace(t *testing.T) { assert.Equal(t, "admin", nss[0].AdminMetadata.UserID) assert.Equal(t, server_structs.RegPending, nss[0].AdminMetadata.Status) assert.NotEqual(t, time.Time{}, nss[0].AdminMetadata.CreatedAt) - server_utils.Reset() + server_utils.ResetTestState() }) } func TestUpdateNamespaceHandler(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() }) _, cancel, egrp := test_utils.TestContext(context.Background(), t) defer func() { require.NoError(t, egrp.Wait()) }() @@ -1389,7 +1389,7 @@ func TestUpdateNamespaceHandler(t *testing.T) { } func TestListInsitutions(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() router := gin.Default() router.GET("/institutions", listInstitutions) @@ -1409,7 +1409,7 @@ func TestListInsitutions(t *testing.T) { }) t.Run("cache-hit-returns", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() mockUrl := url.URL{Scheme: "https", Host: "example.com"} viper.Set("Registry.InstitutionsUrl", mockUrl.String()) mockInsts := []registrationFieldOption{{Name: "Foo", ID: "001"}} @@ -1433,7 +1433,7 @@ func TestListInsitutions(t *testing.T) { }) t.Run("nil-cache-with-nonnil-config-returns", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() optionsCache.DeleteAll() mockInstsConfig := []registrationFieldOption{{Name: "foo", ID: "bar"}} @@ -1457,7 +1457,7 @@ func TestListInsitutions(t *testing.T) { }) t.Run("non-nil-cache-with-nonnil-config-return-config", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() mockUrl := url.URL{Scheme: "https", Host: "example.com"} viper.Set("Registry.InstitutionsUrl", mockUrl.String()) mockInsts := []registrationFieldOption{{Name: "Foo", ID: "001"}} diff --git a/registry/registry_validation_test.go b/registry/registry_validation_test.go index 5e3cc74d1..469844e99 100644 --- a/registry/registry_validation_test.go +++ b/registry/registry_validation_test.go @@ -201,12 +201,12 @@ func TestValidateCustomFields(t *testing.T) { } func TestValidateKeyChaining(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() setupMockRegistryDB(t) defer func() { resetNamespaceDB(t) teardownMockNamespaceDB(t) - server_utils.Reset() + server_utils.ResetTestState() }() _, jwksFoo, jwksStrFoo, err := test_utils.GenerateJWK() diff --git a/server_utils/origin_test.go b/server_utils/origin_test.go index f7376c098..f31d9687a 100644 --- a/server_utils/origin_test.go +++ b/server_utils/origin_test.go @@ -82,13 +82,11 @@ func setup(t *testing.T, config string) []OriginExport { // tests an origin configuration that mimics what you could do with env vars due to the // fact that we don't use a yaml list func TestGetExports(t *testing.T) { - Reset() - ResetOriginExports() + ResetTestState() // Posix tests t.Run("testSingleExportValid", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, envVarMimicConfig) assert.Len(t, exports, 1, "expected 1 export") @@ -101,8 +99,7 @@ func TestGetExports(t *testing.T) { }) t.Run("testMultiExportValid", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, multiExportValidConfig) assert.Len(t, exports, 2, "expected 2 exports") @@ -134,8 +131,7 @@ func TestGetExports(t *testing.T) { }) t.Run("testExportVolumesValid", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, exportVolumesValidConfig) assert.Len(t, exports, 2, "expected 2 exports") @@ -169,8 +165,7 @@ func TestGetExports(t *testing.T) { // When we have a single export volume, we also set a few viper variables that can be // used by sections of code that assume a single export. Test that those are set properly t.Run("testExportVolumesSingle", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, exportSingleVolumeConfig) assert.Len(t, exports, 1, "expected 1 export") @@ -198,8 +193,7 @@ func TestGetExports(t *testing.T) { }) t.Run("testSingleExportBlock", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, singleExportBlockConfig) assert.Len(t, exports, 1, "expected 1 export") @@ -227,8 +221,7 @@ func TestGetExports(t *testing.T) { }) t.Run("testInvalidExport", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() viper.Set("Origin.StorageType", "posix") viper.Set("Origin.ExportVolumes", "") @@ -236,14 +229,14 @@ func TestGetExports(t *testing.T) { assert.Error(t, err) assert.ErrorIs(t, err, ErrInvalidOriginConfig) - Reset() + ResetTestState() viper.Set("Origin.StorageType", "posix") viper.Set("Origin.ExportVolumes", "foo") _, err = GetOriginExports() require.Error(t, err) assert.ErrorIs(t, err, ErrInvalidOriginConfig) - Reset() + ResetTestState() viper.Set("Origin.StorageType", "blah") _, err = GetOriginExports() assert.Error(t, err) @@ -252,8 +245,7 @@ func TestGetExports(t *testing.T) { // S3 tests t.Run("testSingleExportValidS3", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, s3envVarMimicConfig) @@ -270,8 +262,7 @@ func TestGetExports(t *testing.T) { }) t.Run("testMultiExportValidS3", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, s3multiExportValidConfig) assert.Len(t, exports, 2, "expected 2 exports") @@ -305,8 +296,7 @@ func TestGetExports(t *testing.T) { }) t.Run("testExportVolumesValidS3", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, s3exportVolumesValidConfig) assert.Len(t, exports, 2, "expected 2 exports") @@ -340,8 +330,7 @@ func TestGetExports(t *testing.T) { }) t.Run("testExportVolumesSingleS3", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, s3exportSingleVolumeConfig) assert.Len(t, exports, 1, "expected 1 export") @@ -374,8 +363,7 @@ func TestGetExports(t *testing.T) { }) t.Run("testSingleExportBlockS3", func(t *testing.T) { - defer Reset() - defer ResetOriginExports() + defer ResetTestState() exports := setup(t, s3singleExportBlockConfig) assert.Len(t, exports, 1, "expected 1 export") diff --git a/server_utils/registry_test.go b/server_utils/registry_test.go index 5baa067b6..7cd777a88 100644 --- a/server_utils/registry_test.go +++ b/server_utils/registry_test.go @@ -30,7 +30,7 @@ import ( ) func TestGetNSIssuerURL(t *testing.T) { - Reset() + ResetTestState() viper.Set("ConfigDir", t.TempDir()) config.InitConfig() require.NoError(t, config.InitClient()) @@ -39,11 +39,11 @@ func TestGetNSIssuerURL(t *testing.T) { url, err := GetNSIssuerURL("/test-prefix") assert.Equal(t, nil, err) assert.Equal(t, "https://registry.com:8446/api/v1.0/registry/test-prefix", url) - Reset() + ResetTestState() } func TestGetJWKSURLFromIssuerURL(t *testing.T) { - Reset() + ResetTestState() viper.Set("ConfigDir", t.TempDir()) config.InitConfig() require.NoError(t, config.InitClient()) diff --git a/server_utils/server_utils.go b/server_utils/server_utils.go index 7b1c3d456..15fa6b58f 100644 --- a/server_utils/server_utils.go +++ b/server_utils/server_utils.go @@ -272,7 +272,9 @@ func LaunchWatcherMaintenance(ctx context.Context, dirPaths []string, descriptio }) } -func Reset() { +// Reset the testing state, including: +// 1. viper settings, 2. preferred prefix, 3. transport object, 4. Federation metadata, 5. origin exports +func ResetTestState() { config.ResetConfig() ResetOriginExports() } diff --git a/web_ui/authentication_test.go b/web_ui/authentication_test.go index b0bb129e7..d743721b1 100644 --- a/web_ui/authentication_test.go +++ b/web_ui/authentication_test.go @@ -54,7 +54,7 @@ func TestWaitUntilLogin(t *testing.T) { defer cancel() dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", dirName) config.InitConfig() err := config.InitServer(ctx, server_structs.OriginType) @@ -103,7 +103,7 @@ func TestCodeBasedLogin(t *testing.T) { defer cancel() dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", dirName) config.InitConfig() err := config.InitServer(ctx, server_structs.OriginType) @@ -159,7 +159,7 @@ func TestPasswordResetAPI(t *testing.T) { defer cancel() dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", dirName) viper.Set("Origin.Port", 8443) viper.Set("Server.UIPasswordFile", tempPasswdFile.Name()) @@ -301,7 +301,7 @@ func TestPasswordBasedLoginAPI(t *testing.T) { defer cancel() dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", dirName) config.InitConfig() viper.Set("Server.UIPasswordFile", tempPasswdFile.Name()) @@ -419,7 +419,7 @@ func TestWhoamiAPI(t *testing.T) { defer cancel() dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() config.InitConfig() viper.Set("ConfigDir", dirName) viper.Set("Server.UIPasswordFile", tempPasswdFile.Name()) @@ -586,7 +586,7 @@ func TestAdminAuthHandler(t *testing.T) { if tc.expectedError != "" { assert.Contains(t, w.Body.String(), tc.expectedError) } - server_utils.Reset() + server_utils.ResetTestState() }) } } @@ -597,7 +597,7 @@ func TestLogoutAPI(t *testing.T) { defer cancel() dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() config.InitConfig() viper.Set("ConfigDir", dirName) viper.Set("Server.UIPasswordFile", tempPasswdFile.Name()) @@ -678,10 +678,10 @@ func TestListOIDCEnabledServersHandler(t *testing.T) { router := gin.New() router.GET("/oauth", listOIDCEnabledServersHandler) t.Cleanup(func() { - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("registry-included-by-default", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() expected := OIDCEnabledServerRes{ODICEnabledServers: []string{"registry"}} req, err := http.NewRequest("GET", "/oauth", nil) assert.NoError(t, err) @@ -702,7 +702,7 @@ func TestListOIDCEnabledServersHandler(t *testing.T) { }) t.Run("origin-included-if-flag-is-on", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Origin.EnableOIDC", true) expected := OIDCEnabledServerRes{ODICEnabledServers: []string{"registry", "origin"}} req, err := http.NewRequest("GET", "/oauth", nil) @@ -724,7 +724,7 @@ func TestListOIDCEnabledServersHandler(t *testing.T) { }) t.Run("cache-included-if-flag-is-on", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Cache.EnableOIDC", true) expected := OIDCEnabledServerRes{ODICEnabledServers: []string{"registry", "cache"}} req, err := http.NewRequest("GET", "/oauth", nil) @@ -746,7 +746,7 @@ func TestListOIDCEnabledServersHandler(t *testing.T) { }) t.Run("director-included-if-flag-is-on", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Director.EnableOIDC", true) expected := OIDCEnabledServerRes{ODICEnabledServers: []string{"registry", "director"}} req, err := http.NewRequest("GET", "/oauth", nil) @@ -768,7 +768,7 @@ func TestListOIDCEnabledServersHandler(t *testing.T) { }) t.Run("origin-cache-both-included-if-flags-are-on", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Origin.EnableOIDC", true) viper.Set("Cache.EnableOIDC", true) viper.Set("Director.EnableOIDC", true) diff --git a/web_ui/engine_test.go b/web_ui/engine_test.go index 761712c78..c828331cb 100644 --- a/web_ui/engine_test.go +++ b/web_ui/engine_test.go @@ -49,7 +49,7 @@ import ( // Setup a gin engine that will serve up a /ping endpoint on a Unix domain socket. func setupPingEngine(t *testing.T, ctx context.Context, egrp *errgroup.Group) (chan bool, context.CancelFunc, string) { dirname := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Logging.Level", "Debug") viper.Set("ConfigDir", dirname) viper.Set("Server.WebPort", 8444) diff --git a/web_ui/prometheus_test.go b/web_ui/prometheus_test.go index 632a83e85..22197aade 100644 --- a/web_ui/prometheus_test.go +++ b/web_ui/prometheus_test.go @@ -50,7 +50,7 @@ func TestPrometheusUnprotected(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() av1 := route.New().WithPrefix("/api/v1.0/prometheus") av1.Get("/query", func(w http.ResponseWriter, r *http.Request) { @@ -103,7 +103,7 @@ func TestPrometheusProtectionCookieAuth(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() av1 := route.New().WithPrefix("/api/v1.0/prometheus") @@ -162,7 +162,7 @@ func TestPrometheusProtectionOriginHeaderScope(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Server.ExternalWebUrl", "https://test-origin.org:8444") viper.Set("Monitoring.PromQLAuthorization", true) diff --git a/web_ui/ui_test.go b/web_ui/ui_test.go index e87e5acc9..a57c8e1e2 100644 --- a/web_ui/ui_test.go +++ b/web_ui/ui_test.go @@ -209,12 +209,12 @@ func TestHandleWebUIAuth(t *testing.T) { }) t.Run("403-for-logged-in-non-admin-user", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() // We let the frontend to handle unauthorized user (if the password is initialzied) setupTestAuthDB(t) t.Cleanup(func() { cleanupAuthDB() - server_utils.Reset() + server_utils.ResetTestState() }) tmpDir := t.TempDir() diff --git a/web_ui/ui_unix_test.go b/web_ui/ui_unix_test.go index 04c0b9b24..dbdcbc5a1 100644 --- a/web_ui/ui_unix_test.go +++ b/web_ui/ui_unix_test.go @@ -35,7 +35,7 @@ import ( ) func TestDoReload(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() savedAuthDB := authDB.Load() authDB.Store(nil) defer authDB.Store(savedAuthDB) diff --git a/xrootd/authorization_test.go b/xrootd/authorization_test.go index 66fd44060..f1b69a8cd 100644 --- a/xrootd/authorization_test.go +++ b/xrootd/authorization_test.go @@ -164,7 +164,7 @@ func TestOSDFAuthRetrieval(t *testing.T) { transport.TLSClientConfig = oldConfig }) - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Federation.TopologyUrl", "https://topology.opensciencegrid.org/") viper.Set("Server.Hostname", "sc-origin.chtc.wisc.edu") @@ -172,7 +172,7 @@ func TestOSDFAuthRetrieval(t *testing.T) { _, err := getOSDFAuthFiles(originServer) require.NoError(t, err, "error") - server_utils.Reset() + server_utils.ResetTestState() } func TestOSDFAuthCreation(t *testing.T) { @@ -261,9 +261,9 @@ func TestOSDFAuthCreation(t *testing.T) { for _, testInput := range tests { t.Run(testInput.desc, func(t *testing.T) { dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Xrootd.Authfile", filepath.Join(dirName, "authfile")) viper.Set("Federation.TopologyUrl", ts.URL) @@ -300,7 +300,7 @@ func TestOSDFAuthCreation(t *testing.T) { require.NoError(t, err, "Error reading generated authfile") require.Equal(t, testInput.authOut, string(genAuth)) - server_utils.Reset() + server_utils.ResetTestState() }) } } @@ -337,9 +337,9 @@ func TestEmitAuthfile(t *testing.T) { for _, testInput := range tests { t.Run(testInput.desc, func(t *testing.T) { dirName := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Xrootd.Authfile", filepath.Join(dirName, "authfile")) viper.Set("Origin.RunLocation", dirName) @@ -363,9 +363,9 @@ func TestEmitAuthfile(t *testing.T) { func TestEmitCfg(t *testing.T) { dirname := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Origin.RunLocation", dirname) err := config.InitClient() @@ -443,9 +443,9 @@ func TestDeduplicateBasePaths(t *testing.T) { func TestLoadScitokensConfig(t *testing.T) { dirname := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Origin.RunLocation", dirname) err := config.InitClient() @@ -478,9 +478,9 @@ func TestLoadScitokensConfig(t *testing.T) { // Test that merging the configuration works without throwing any errors func TestMergeConfig(t *testing.T) { dirname := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Origin.RunLocation", dirname) viper.Set("Origin.Port", 8443) @@ -527,9 +527,9 @@ func TestGenerateConfig(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Origin.SelfTest", false) issuer, err := GenerateMonitoringIssuer() @@ -552,7 +552,7 @@ func TestGenerateConfig(t *testing.T) { assert.Equal(t, "/pelican/monitoring", issuer.BasePaths[0]) assert.Equal(t, "xrootd", issuer.DefaultUser) - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Origin.SelfTest", false) viper.Set("Origin.ScitokensDefaultUser", "user1") viper.Set("Origin.ScitokensMapSubject", true) @@ -574,11 +574,11 @@ func TestGenerateConfig(t *testing.T) { } func TestWriteOriginAuthFiles(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() originAuthTester := func(server server_structs.XRootDServer, authStart string, authResult string) func(t *testing.T) { return func(t *testing.T) { - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Origin.StorageType", "posix") dirname := t.TempDir() @@ -625,7 +625,7 @@ func TestWriteCacheAuthFiles(t *testing.T) { return func(t *testing.T) { dirname := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Cache.RunLocation", dirname) if server.GetServerType().IsEnabled(server_structs.OriginType) { viper.Set("Xrootd.ScitokensConfig", filepath.Join(dirname, "scitokens-origin-generated.cfg")) @@ -734,7 +734,7 @@ func TestWriteOriginScitokensConfig(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() dirname := t.TempDir() os.Setenv("PELICAN_ORIGIN_RUNLOCATION", dirname) defer os.Unsetenv("PELICAN_ORIGIN_RUNLOCATION") diff --git a/xrootd/fed_test.go b/xrootd/fed_test.go index 303eed48e..f46528122 100644 --- a/xrootd/fed_test.go +++ b/xrootd/fed_test.go @@ -50,10 +50,10 @@ var ( ) func TestHttpOriginConfig(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() viper.Set("ConfigDir", t.TempDir()) server_utils.ResetOriginExports() - defer server_utils.Reset() + defer server_utils.ResetTestState() body := "Hello, World!" srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/xrootd/origin_test.go b/xrootd/origin_test.go index 2bf0ca27d..e2c6a696d 100644 --- a/xrootd/origin_test.go +++ b/xrootd/origin_test.go @@ -152,9 +152,9 @@ func TestOrigin(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Origin.StoragePrefix", t.TempDir()) viper.Set("Origin.FederationPrefix", "/test") @@ -190,8 +190,8 @@ func TestMultiExportOrigin(t *testing.T) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() - defer server_utils.Reset() + server_utils.ResetTestState() + defer server_utils.ResetTestState() viper.SetConfigType("yaml") // Use viper to read in the embedded config @@ -236,9 +236,9 @@ func runS3Test(t *testing.T, bucketName, urlStyle, objectName string) { defer func() { require.NoError(t, egrp.Wait()) }() defer cancel() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() federationPrefix := "/test" regionName := "us-east-1" diff --git a/xrootd/xrootd_config_test.go b/xrootd/xrootd_config_test.go index d009ea464..204324112 100644 --- a/xrootd/xrootd_config_test.go +++ b/xrootd/xrootd_config_test.go @@ -52,7 +52,7 @@ type xrootdTest struct { } func (x *xrootdTest) setup() { - server_utils.Reset() + server_utils.ResetTestState() dirname, err := os.MkdirTemp("", "tmpDir") require.NoError(x.T, err) @@ -83,9 +83,9 @@ func TestXrootDOriginConfig(t *testing.T) { t.Cleanup(func() { os.RemoveAll(dirname) }) - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Configdir", dirname) viper.Set("Origin.RunLocation", dirname) @@ -117,7 +117,7 @@ func TestXrootDOriginConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "cms.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOriginCmsIncorrectConfig", func(t *testing.T) { @@ -131,7 +131,7 @@ func TestXrootDOriginConfig(t *testing.T) { configPath, err := ConfigXrootd(ctx, true) require.Error(t, err) assert.NotNil(t, configPath) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOriginScitokensCorrectConfig", func(t *testing.T) { @@ -154,7 +154,7 @@ func TestXrootDOriginConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "scitokens.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOriginScitokensIncorrectConfig", func(t *testing.T) { @@ -168,7 +168,7 @@ func TestXrootDOriginConfig(t *testing.T) { configPath, err := ConfigXrootd(ctx, true) require.Error(t, err) assert.NotNil(t, configPath) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOriginXrdCorrectConfig", func(t *testing.T) { @@ -191,7 +191,7 @@ func TestXrootDOriginConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "xrd.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOriginXrdIncorrectConfig", func(t *testing.T) { @@ -205,7 +205,7 @@ func TestXrootDOriginConfig(t *testing.T) { configPath, err := ConfigXrootd(ctx, true) require.Error(t, err) assert.NotNil(t, configPath) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOriginXrootdCorrectConfig", func(t *testing.T) { @@ -228,7 +228,7 @@ func TestXrootDOriginConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "xrootd.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOriginXrootdIncorrectConfig", func(t *testing.T) { @@ -242,7 +242,7 @@ func TestXrootDOriginConfig(t *testing.T) { configPath, err := ConfigXrootd(ctx, true) require.Error(t, err) assert.NotNil(t, configPath) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOsdfWithXRDHOSTAndPort", func(t *testing.T) { @@ -259,7 +259,7 @@ func TestXrootDOriginConfig(t *testing.T) { assert.NotNil(t, configPath) assert.Equal(t, "my-xrootd.com", os.Getenv("XRDHOST")) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestOsdfWithXRDHOSTAndNoPort", func(t *testing.T) { @@ -276,7 +276,7 @@ func TestXrootDOriginConfig(t *testing.T) { assert.NotNil(t, configPath) assert.Equal(t, "my-xrootd.com", os.Getenv("XRDHOST")) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestPelicanWithXRDHOST", func(t *testing.T) { @@ -294,7 +294,7 @@ func TestXrootDOriginConfig(t *testing.T) { _, xrdhostIsSet := os.LookupEnv("XRDHOST") assert.False(t, xrdhostIsSet, "XRDHOST should only be set in OSDF mode") - server_utils.Reset() + server_utils.ResetTestState() }) } @@ -308,7 +308,7 @@ func TestXrootDCacheConfig(t *testing.T) { t.Cleanup(func() { os.RemoveAll(dirname) }) - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Cache.RunLocation", dirname) viper.Set("ConfigDir", dirname) @@ -318,7 +318,7 @@ func TestXrootDCacheConfig(t *testing.T) { assert.NotNil(t, configPath) t.Run("TestCacheThrottlePluginEnabled", func(t *testing.T) { - defer server_utils.Reset() + defer server_utils.ResetTestState() xrootd := xrootdTest{T: t} xrootd.setup() @@ -343,7 +343,7 @@ func TestXrootDCacheConfig(t *testing.T) { }) t.Run("TestCacheThrottlePluginDisabled", func(t *testing.T) { - defer server_utils.Reset() + defer server_utils.ResetTestState() xrootd := xrootdTest{T: t} xrootd.setup() @@ -384,7 +384,7 @@ func TestXrootDCacheConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "ofs.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestCacheOfsIncorrectConfig", func(t *testing.T) { @@ -420,7 +420,7 @@ func TestXrootDCacheConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "pfc.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestCachePfcIncorrectConfig", func(t *testing.T) { @@ -434,7 +434,7 @@ func TestXrootDCacheConfig(t *testing.T) { configPath, err := ConfigXrootd(ctx, true) require.Error(t, err) assert.NotNil(t, configPath) - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestCachePssCorrectConfig", func(t *testing.T) { @@ -457,7 +457,7 @@ func TestXrootDCacheConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "pss.setopt DebugLevel 4") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestCachePssIncorrectConfig", func(t *testing.T) { @@ -493,7 +493,7 @@ func TestXrootDCacheConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "scitokens.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestCacheScitokensIncorrectConfig", func(t *testing.T) { @@ -529,7 +529,7 @@ func TestXrootDCacheConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "xrd.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestCacheXrdIncorrectConfig", func(t *testing.T) { @@ -565,7 +565,7 @@ func TestXrootDCacheConfig(t *testing.T) { content, err := io.ReadAll(file) assert.NoError(t, err) assert.Contains(t, string(content), "xrootd.trace debug") - server_utils.Reset() + server_utils.ResetTestState() }) t.Run("TestCacheXrootdIncorrectConfig", func(t *testing.T) { @@ -589,9 +589,9 @@ func TestUpdateAuth(t *testing.T) { runDirname := t.TempDir() configDirname := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() - defer server_utils.Reset() + defer server_utils.ResetTestState() viper.Set("Logging.Level", "Debug") viper.Set("Origin.RunLocation", runDirname) @@ -686,7 +686,7 @@ func TestCopyCertificates(t *testing.T) { runDirname := t.TempDir() configDirname := t.TempDir() - server_utils.Reset() + server_utils.ResetTestState() viper.Set("Logging.Level", "Debug") viper.Set("Origin.RunLocation", runDirname) viper.Set("ConfigDir", configDirname) @@ -770,9 +770,9 @@ func TestCopyCertificates(t *testing.T) { } func TestAuthIntervalUnmarshal(t *testing.T) { - defer server_utils.Reset() + defer server_utils.ResetTestState() t.Run("test-minutes-to-seconds", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() var xrdConfig XrootdConfig viper.Set("Xrootd.AuthRefreshInterval", "5m") err := viper.Unmarshal(&xrdConfig, viper.DecodeHook(combinedDecodeHookFunc())) @@ -781,7 +781,7 @@ func TestAuthIntervalUnmarshal(t *testing.T) { }) t.Run("test-hours-to-seconds", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() var xrdConfig XrootdConfig viper.Set("Xrootd.AuthRefreshInterval", "24h") err := viper.Unmarshal(&xrdConfig, viper.DecodeHook(combinedDecodeHookFunc())) @@ -790,7 +790,7 @@ func TestAuthIntervalUnmarshal(t *testing.T) { }) t.Run("test-seconds-to-seconds", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() var xrdConfig XrootdConfig viper.Set("Xrootd.AuthRefreshInterval", "100s") err := viper.Unmarshal(&xrdConfig, viper.DecodeHook(combinedDecodeHookFunc())) @@ -799,7 +799,7 @@ func TestAuthIntervalUnmarshal(t *testing.T) { }) t.Run("test-less-than-60s", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() var xrdConfig XrootdConfig viper.Set("Xrootd.AuthRefreshInterval", "10") err := viper.Unmarshal(&xrdConfig, viper.DecodeHook(combinedDecodeHookFunc())) @@ -809,7 +809,7 @@ func TestAuthIntervalUnmarshal(t *testing.T) { }) t.Run("test-no-suffix-to-seconds", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() var xrdConfig XrootdConfig viper.Set("Xrootd.AuthRefreshInterval", "99") err := viper.Unmarshal(&xrdConfig, viper.DecodeHook(combinedDecodeHookFunc())) @@ -818,7 +818,7 @@ func TestAuthIntervalUnmarshal(t *testing.T) { }) t.Run("test-less-than-second", func(t *testing.T) { - server_utils.Reset() + server_utils.ResetTestState() var xrdConfig XrootdConfig viper.Set("Xrootd.AuthRefreshInterval", "0.5s") err := viper.Unmarshal(&xrdConfig, viper.DecodeHook(combinedDecodeHookFunc()))