Skip to content

Commit f55f544

Browse files
author
Emma Turetsky
committed
Fixed failing tests because of config dir
-- Mostly due to unset ConfigDir that should be a tempDir -- Adjusted some params and a few other tests as well
1 parent 1370e8d commit f55f544

6 files changed

Lines changed: 43 additions & 17 deletions

File tree

client/director_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import (
3131
log "github.com/sirupsen/logrus"
3232
"github.com/spf13/viper"
3333
"github.com/stretchr/testify/assert"
34+
"github.com/stretchr/testify/require"
3435

36+
"github.com/pelicanplatform/pelican/config"
3537
"github.com/pelicanplatform/pelican/param"
3638
"github.com/pelicanplatform/pelican/pelican_url"
3739
"github.com/pelicanplatform/pelican/server_structs"
@@ -105,6 +107,10 @@ func TestQueryDirector(t *testing.T) {
105107
server_utils.ResetTestState()
106108
defer server_utils.ResetTestState()
107109
viper.Set(param.Client_DirectorRetries.GetName(), 3)
110+
// This test assumes the debugging level is at debug or higher
111+
viper.Set(param.Debug.GetName(), true)
112+
err := config.InitClient()
113+
require.NoError(t, err)
108114

109115
type testCase struct {
110116
name string

cmd/plugin_test.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ import (
6464
var (
6565
//go:embed resources/test-https-origin.yml
6666
httpsOriginConfig string
67+
68+
//go:embed resources/public-test-origin.yml
69+
publicTestOrigin string
6770
)
6871

6972
// TestReadMultiTransfer test if we can read multiple transfers from stdin
@@ -494,11 +497,7 @@ func TestPluginMulti(t *testing.T) {
494497

495498
dirName := t.TempDir()
496499

497-
viper.Set("Logging.Level", "debug")
498-
viper.Set("Origin.StorageType", "posix")
499-
viper.Set("Origin.ExportVolumes", "/test")
500-
viper.Set("Origin.EnablePublicReads", true)
501-
fed := fed_test_utils.NewFedTest(t, "")
500+
fed := fed_test_utils.NewFedTest(t, publicTestOrigin)
502501
host := param.Server_Hostname.GetString() + ":" + strconv.Itoa(param.Server_WebPort.GetInt())
503502

504503
// Drop the testFileContent into the origin directory
@@ -846,12 +845,7 @@ func TestPluginRecursiveDownload(t *testing.T) {
846845

847846
dirName := t.TempDir()
848847

849-
viper.Set("Logging.Level", "debug")
850-
viper.Set("Origin.StorageType", "posix")
851-
viper.Set("Origin.FederationPrefix", "/test")
852-
viper.Set("Origin.StoragePrefix", "/<THIS WILL BE OVERRIDDEN>")
853-
viper.Set("Origin.EnablePublicReads", true)
854-
fed := fed_test_utils.NewFedTest(t, "")
848+
fed := fed_test_utils.NewFedTest(t, publicTestOrigin)
855849
host := param.Server_Hostname.GetString() + ":" + strconv.Itoa(param.Server_WebPort.GetInt())
856850

857851
// Drop the testFileContent into the origin directory
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Origin export configuration to test full multi-export capabilities
2+
3+
Origin:
4+
# Things that configure the origin itself
5+
StorageType: "posix"
6+
EnableDirectReads: true
7+
# The actual namespaces we export
8+
Exports:
9+
- StoragePrefix: /<SHOULD BE OVERRIDDEN>
10+
FederationPrefix: /test
11+
# Don't set Reads -- it should be toggled true by setting PublicReads
12+
Capabilities: ["PublicReads", "Writes", "DirectReads", "Listings"]

config/config_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,14 @@ func TestInitServerUrl(t *testing.T) {
569569
t.Cleanup(func() {
570570
ResetConfig()
571571
})
572+
initConfig := func() {
573+
ResetConfig()
574+
tempDir := t.TempDir()
575+
viper.Set("ConfigDir", tempDir)
576+
}
572577

573578
initDirectoryConfig := func() {
579+
initConfig()
574580
viper.Set("Director.MinStatResponse", 1)
575581
viper.Set("Director.MaxStatResponse", 4)
576582
}
@@ -637,6 +643,7 @@ func TestInitServerUrl(t *testing.T) {
637643

638644
t.Run("reg-url-default-to-web-url", func(t *testing.T) {
639645
// We respect the URL value set directly by others. Won't remove 443 port
646+
initConfig()
640647
// If Server_ExternalWebUrl is not set, Federation_RegistryUrl defaults to https://<hostname>:<non-443-port>
641648
// In this case, the port is 443, so Federation_RegistryUrl = https://example.com
642649
viper.Set("Server.Hostname", mockHostname)
@@ -649,13 +656,15 @@ func TestInitServerUrl(t *testing.T) {
649656

650657
// If Server_ExternalWebUrl is explicitly set, Federation_RegistryUrl defaults to whatever it is
651658
// But 443 port is stripped if provided
659+
initConfig()
652660
viper.Set("Server.ExternalWebUrl", mockWebUrlW443Port)
653661
err = InitServer(ctx, server_structs.RegistryType)
654662
require.NoError(t, err)
655663
fedInfo, err = GetFederation(ctx)
656664
require.NoError(t, err)
657665
assert.Equal(t, mockWebUrlWoPort, fedInfo.RegistryEndpoint)
658666

667+
initConfig()
659668
viper.Set("Server.ExternalWebUrl", mockWebUrlWoPort)
660669
viper.Set("Federation.RegistryUrl", "https://example-registry.com")
661670
err = InitServer(ctx, server_structs.RegistryType)
@@ -667,6 +676,7 @@ func TestInitServerUrl(t *testing.T) {
667676

668677
t.Run("broker-url-default-to-web-url", func(t *testing.T) {
669678
// We respect the URL value set directly by others. Won't remove 443 port
679+
initConfig()
670680
// If Server_ExternalWebUrl is not set, Federation_BrokerUrl defaults to https://<hostname>:<non-443-port>
671681
// In this case, the port is 443, so Federation_BrokerUrl = https://example.com
672682
viper.Set("Server.Hostname", mockHostname)
@@ -679,13 +689,15 @@ func TestInitServerUrl(t *testing.T) {
679689

680690
// If Server_ExternalWebUrl is explicitly set, Federation_BrokerUrl defaults to whatever it is
681691
// But 443 port is stripped if provided
692+
initConfig()
682693
viper.Set("Server.ExternalWebUrl", mockWebUrlW443Port)
683694
err = InitServer(ctx, server_structs.BrokerType)
684695
require.NoError(t, err)
685696
fedInfo, err = GetFederation(ctx)
686697
require.NoError(t, err)
687698
assert.Equal(t, mockWebUrlWoPort, fedInfo.BrokerEndpoint)
688699

700+
initConfig()
689701
viper.Set("Server.ExternalWebUrl", mockWebUrlWoPort)
690702
viper.Set("Federation.BrokerUrl", "https://example-registry.com")
691703
err = InitServer(ctx, server_structs.BrokerType)

director/fed_token_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ func TestCreateFedTok(t *testing.T) {
178178
server_utils.ResetTestState()
179179
defer server_utils.ResetTestState()
180180

181-
kDir := filepath.Join(t.TempDir(), "keys")
182-
viper.Set(param.IssuerKeysDirectory.GetName(), kDir)
183-
viper.Set("ConfigDir", t.TempDir())
184-
185181
testCases := []struct {
186182
name string
187183
host string
@@ -223,10 +219,14 @@ func TestCreateFedTok(t *testing.T) {
223219

224220
for _, tc := range testCases {
225221
t.Run(tc.name, func(t *testing.T) {
226-
// config.ResetFederationForTest()
227222
w := httptest.NewRecorder()
228223
c, _ := gin.CreateTestContext(w)
229224

225+
confDir := t.TempDir()
226+
kDir := filepath.Join(confDir, "keys")
227+
viper.Set(param.IssuerKeysDirectory.GetName(), kDir)
228+
viper.Set("ConfigDir", confDir)
229+
230230
config.ResetFederationForTest()
231231
fed := pelican_url.FederationDiscovery{
232232
// Most of these aren't actually used by the test, but to prevent auto discovery

lotman/lotman_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package lotman
2222

2323
import (
2424
"bytes"
25+
"context"
2526
_ "embed"
2627
"encoding/json"
2728
"fmt"
@@ -101,7 +102,7 @@ func setupLotmanFromConf(t *testing.T, readConfig bool, name string, discUrl str
101102
// If we're not reading from the embedded yaml, grab the
102103
// default configuration. We need _some_ configuration to work.
103104
viper.Set("ConfigDir", t.TempDir())
104-
config.InitServer(server_structs.CacheType)
105+
config.InitServer(context.Background(), server_structs.CacheType)
105106
}
106107

107108
tmpPathPattern := name + "*"
@@ -147,6 +148,7 @@ func TestLotmanInit(t *testing.T) {
147148

148149
t.Run("TestGoodInit", func(t *testing.T) {
149150
viper.Set("Log.Level", "debug")
151+
viper.Set("Cache.DataLocations", []string{})
150152
server := getMockDiscoveryHost()
151153
// Set the Federation.DiscoveryUrl to the test server's URL
152154
// Lotman uses the discovered URLs/keys to determine some aspects of lot ownership

0 commit comments

Comments
 (0)