From 20fbc9367c13ab2b2b3aa92328b157005050dcde Mon Sep 17 00:00:00 2001 From: Justin Hiemstra Date: Tue, 26 Nov 2024 21:34:07 +0000 Subject: [PATCH] Use updated params throughout tests Turns out some tests don't call init config, so they weren't handling the deprecated config. This updates the test to use the new params so they set the correct values. --- cache/cache_api.go | 8 ++++---- cache/cache_api_test.go | 4 ++-- cache/self_monitor.go | 8 ++++---- client/fed_test.go | 2 +- cmd/fed_serve_cache_test.go | 2 +- fed_test_utils/fed.go | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cache/cache_api.go b/cache/cache_api.go index ae4f38823..a47f18ce7 100644 --- a/cache/cache_api.go +++ b/cache/cache_api.go @@ -37,7 +37,7 @@ import ( func CheckCacheSentinelLocation() error { if param.Cache_SentinelLocation.IsSet() { sentinelPath := param.Cache_SentinelLocation.GetString() - dataLoc := param.Cache_LocalRoot.GetString() + dataLoc := param.Cache_StorageLocation.GetString() sentinelPath = path.Clean(sentinelPath) if path.Base(sentinelPath) != sentinelPath { return errors.Errorf("invalid Cache.SentinelLocation path. File must not contain a directory. Got %s", sentinelPath) @@ -51,17 +51,17 @@ func CheckCacheSentinelLocation() error { return nil } -// Periodically scan the //pelican/monitoring directory to clean up test files +// Periodically scan the ${Cache.StorageLocation}/pelican/monitoring directory to clean up test files // TODO: Director test files should be under /pelican/monitoring/directorTest and the file names // should have director-test- as the prefix func LaunchDirectorTestFileCleanup(ctx context.Context) { server_utils.LaunchWatcherMaintenance(ctx, - []string{filepath.Join(param.Cache_LocalRoot.GetString(), "pelican", "monitoring")}, + []string{filepath.Join(param.Cache_StorageLocation.GetString(), "pelican", "monitoring")}, "cache director-based health test clean up", time.Minute, func(notifyEvent bool) error { // We run this function regardless of notifyEvent to do the cleanup - dirPath := filepath.Join(param.Cache_LocalRoot.GetString(), "pelican", "monitoring") + dirPath := filepath.Join(param.Cache_StorageLocation.GetString(), "pelican", "monitoring") dirInfo, err := os.Stat(dirPath) if err != nil { return err diff --git a/cache/cache_api_test.go b/cache/cache_api_test.go index 22694622f..a9ce4c318 100644 --- a/cache/cache_api_test.go +++ b/cache/cache_api_test.go @@ -50,7 +50,7 @@ func TestCheckCacheSentinelLocation(t *testing.T) { tmpDir := t.TempDir() server_utils.ResetTestState() viper.Set(param.Cache_SentinelLocation.GetName(), "test.txt") - viper.Set(param.Cache_LocalRoot.GetName(), tmpDir) + viper.Set(param.Cache_StorageLocation.GetName(), tmpDir) err := CheckCacheSentinelLocation() require.Error(t, err) assert.Contains(t, err.Error(), "failed to open Cache.SentinelLocation") @@ -61,7 +61,7 @@ func TestCheckCacheSentinelLocation(t *testing.T) { server_utils.ResetTestState() viper.Set(param.Cache_SentinelLocation.GetName(), "test.txt") - viper.Set(param.Cache_LocalRoot.GetName(), tmpDir) + viper.Set(param.Cache_StorageLocation.GetName(), tmpDir) file, err := os.Create(filepath.Join(tmpDir, "test.txt")) require.NoError(t, err) diff --git a/cache/self_monitor.go b/cache/self_monitor.go index 0bd94706d..44a801dd5 100644 --- a/cache/self_monitor.go +++ b/cache/self_monitor.go @@ -59,7 +59,7 @@ func InitSelfTestDir() error { return err } - basePath := param.Cache_LocalRoot.GetString() + basePath := param.Cache_StorageLocation.GetString() pelicanMonPath := filepath.Join(basePath, "/pelican") monitoringPath := filepath.Join(pelicanMonPath, "/monitoring") selfTestPath := filepath.Join(monitoringPath, "/selfTest") @@ -80,9 +80,9 @@ func InitSelfTestDir() error { } func generateTestFile() (string, error) { - basePath := param.Cache_LocalRoot.GetString() + basePath := param.Cache_StorageLocation.GetString() if basePath == "" { - return "", errors.New("failed to generate self-test file for cache: Cache.LocalRoot is not set.") + return "", errors.New("failed to generate self-test file for cache: Cache.StorageLocation is not set.") } selfTestPath := filepath.Join(basePath, selfTestDir) _, err := os.Stat(selfTestPath) @@ -225,7 +225,7 @@ func downloadTestFile(ctx context.Context, fileUrl string) error { } func deleteTestFile(fileUrlStr string) error { - basePath := param.Cache_LocalRoot.GetString() + basePath := param.Cache_StorageLocation.GetString() fileUrl, err := url.Parse(fileUrlStr) if err != nil { return errors.Wrap(err, "invalid file url to remove the test file") diff --git a/client/fed_test.go b/client/fed_test.go index a066177fc..17b6cfb5f 100644 --- a/client/fed_test.go +++ b/client/fed_test.go @@ -623,7 +623,7 @@ func TestDirectReads(t *testing.T) { assert.Equal(t, transferResults[0].TransferredBytes, int64(17)) // Assert that the file was not cached - cacheDataLocation := param.Cache_LocalRoot.GetString() + export.FederationPrefix + cacheDataLocation := param.Cache_StorageLocation.GetString() + export.FederationPrefix filepath := filepath.Join(cacheDataLocation, filepath.Base(tempFile.Name())) _, err = os.Stat(filepath) assert.True(t, os.IsNotExist(err)) diff --git a/cmd/fed_serve_cache_test.go b/cmd/fed_serve_cache_test.go index 22a7b29c5..359c3b70d 100644 --- a/cmd/fed_serve_cache_test.go +++ b/cmd/fed_serve_cache_test.go @@ -77,7 +77,7 @@ func TestFedServeCache(t *testing.T) { viper.Set("ConfigDir", tmpPath) viper.Set("Origin.RunLocation", filepath.Join(tmpPath, "xOrigin")) viper.Set("Cache.RunLocation", filepath.Join(tmpPath, "xCache")) - viper.Set("Cache.LocalRoot", filepath.Join(tmpPath, "data")) + viper.Set("Cache.StorageLocation", filepath.Join(tmpPath, "data")) viper.Set("Origin.StoragePrefix", filepath.Join(origPath, "ns")) viper.Set("Origin.FederationPrefix", "/test") testFilePath := filepath.Join(origPath, "ns", "test-file.txt") diff --git a/fed_test_utils/fed.go b/fed_test_utils/fed.go index 300ffe27d..15973fab2 100644 --- a/fed_test_utils/fed.go +++ b/fed_test_utils/fed.go @@ -142,7 +142,7 @@ func NewFedTest(t *testing.T, originConfig string) (ft *FedTest) { viper.Set("Server.WebPort", 0) viper.Set("Origin.RunLocation", filepath.Join(tmpPath, "origin")) viper.Set("Cache.RunLocation", filepath.Join(tmpPath, "cache")) - viper.Set("Cache.LocalRoot", filepath.Join(tmpPath, "xcache-data")) + viper.Set("Cache.StorageLocation", filepath.Join(tmpPath, "xcache-data")) viper.Set("LocalCache.RunLocation", filepath.Join(tmpPath, "local-cache")) viper.Set("Registry.RequireOriginApproval", false) viper.Set("Registry.RequireCacheApproval", false)