Skip to content

Commit

Permalink
Fixes to pass unit tests
Browse files Browse the repository at this point in the history
All that was needed was allowing an empty string for setPreferredPrefix
  • Loading branch information
joereuss12 committed Mar 27, 2024
1 parent 54e3b29 commit b61db17
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion client/handle_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ func TestNewPelicanURL(t *testing.T) {
viper.Reset()
viper.Set("TLSSkipVerify", true)
config.InitConfig()
config.InitClient()
err := config.InitClient()
assert.NoError(t, err)
// Create a server that gives us a mock response
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// make our response:
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ var (
string(Pelican): true,
string(OSDF): true,
string(Stash): true,
"": true,
}
)

Expand Down
15 changes: 13 additions & 2 deletions namespaces/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os"
"testing"

log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -103,7 +104,12 @@ func TestMatchNamespace(t *testing.T) {
// Reset the prefix to get old OSDF fallback behavior.
oldPrefix, err := config.SetPreferredPrefix("OSDF")
assert.NoError(t, err)
defer config.SetPreferredPrefix(oldPrefix)
defer func() {
_, err := config.SetPreferredPrefix(oldPrefix)
if err != nil {
log.Errorln(err)
}
}()

viper.Reset()
err = config.InitClient()
Expand Down Expand Up @@ -251,7 +257,12 @@ func TestGetNamespaces(t *testing.T) {
os.Setenv("OSDF_TOPOLOGY_NAMESPACE_URL", "https://doesnotexist.org.blah/namespaces.json")
oldPrefix, err := config.SetPreferredPrefix("OSDF")
assert.NoError(t, err)
defer config.SetPreferredPrefix(oldPrefix)
defer func() {
_, err := config.SetPreferredPrefix(oldPrefix)
if err != nil {
log.Errorln(err)
}
}()
viper.Reset()
err = config.InitClient()
assert.Nil(t, err)
Expand Down
8 changes: 7 additions & 1 deletion xrootd/authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/pelicanplatform/pelican/server_structs"
"github.com/pelicanplatform/pelican/server_utils"
"github.com/pelicanplatform/pelican/test_utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -278,7 +279,12 @@ func TestOSDFAuthCreation(t *testing.T) {
}
oldPrefix, err := config.SetPreferredPrefix("OSDF")
assert.NoError(t, err)
defer config.SetPreferredPrefix(oldPrefix)
defer func() {
_, err := config.SetPreferredPrefix(oldPrefix)
if err != nil {
log.Errorln(err)
}
}()

err = os.WriteFile(filepath.Join(dirName, "authfile"), []byte(testInput.authIn), fs.FileMode(0600))
require.NoError(t, err, "Failure writing test input authfile")
Expand Down

0 comments on commit b61db17

Please sign in to comment.