Skip to content

Commit

Permalink
Clean up from merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
joereuss12 committed Apr 1, 2024
1 parent cf3e85e commit 5ce04d5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
25 changes: 20 additions & 5 deletions client/fed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package client_test

import (
"context"
_ "embed"
"fmt"
"net/url"
Expand All @@ -40,6 +41,7 @@ import (
"github.com/pelicanplatform/pelican/fed_test_utils"
"github.com/pelicanplatform/pelican/param"
"github.com/pelicanplatform/pelican/server_utils"
"github.com/pelicanplatform/pelican/test_utils"
"github.com/pelicanplatform/pelican/token"
"github.com/pelicanplatform/pelican/token_scopes"
)
Expand Down Expand Up @@ -457,7 +459,10 @@ func TestStatHttp(t *testing.T) {
// Set path for object to upload/download
tempPath := tempFile.Name()
fileName := filepath.Base(tempPath)
uploadURL := fmt.Sprintf("pelican://%s/%s", ((*fed.Exports)[0]).FederationPrefix, fileName)
uploadURL := fmt.Sprintf("pelican://%s:%s%s/%s", param.Server_Hostname.GetString(), strconv.Itoa(param.Server_WebPort.GetInt()),
((*fed.Exports)[0]).FederationPrefix, fileName)

log.Errorln(uploadURL)

// Download the file with GET. Shouldn't need a token to succeed
objectSize, err := client.DoStat(ctx, uploadURL)
Expand All @@ -468,6 +473,8 @@ func TestStatHttp(t *testing.T) {
})

t.Run("testStatHttpOSDFScheme", func(t *testing.T) {
_, err := config.SetPreferredPrefix("OSDF")
assert.NoError(t, err)
testFileContent := "test file content"
// Drop the testFileContent into the origin directory
tempFile, err := os.Create(filepath.Join(((*fed.Exports)[0]).StoragePrefix, "test.txt"))
Expand All @@ -478,11 +485,19 @@ func TestStatHttp(t *testing.T) {

viper.Set("Logging.DisableProgressBars", true)

// Set path for object to upload/download
tempPath := tempFile.Name()
fileName := filepath.Base(tempPath)
// Minimal fix of test as it is soon to be replaced
uploadURL := fmt.Sprintf("pelican://%s/%s", ((*fed.Exports)[0]).FederationPrefix, fileName)

uploadURL := fmt.Sprintf("osdf://%s/%s", ((*fed.Exports)[0]).FederationPrefix, fileName)
hostname := fmt.Sprintf("%v:%v", param.Server_WebHost.GetString(), param.Server_WebPort.GetInt())

// Set our metadata values in config since that is what this url scheme - prefix combo does in handle_http
metadata, err := config.DiscoverUrlFederation(fed.Ctx, "https://"+hostname)
assert.NoError(t, err)
viper.Set("Federation.DirectorUrl", metadata.DirectorEndpoint)
viper.Set("Federation.RegistryUrl", metadata.NamespaceRegistrationEndpoint)
viper.Set("Federation.DiscoveryUrl", hostname)
log.Errorln(uploadURL)

// Download the file with GET. Shouldn't need a token to succeed
objectSize, err := client.DoStat(ctx, uploadURL)
Expand Down Expand Up @@ -512,6 +527,6 @@ func TestStatHttp(t *testing.T) {
objectSize, err := client.DoStat(ctx, uploadURL)
assert.Error(t, err)
assert.Equal(t, uint64(0), objectSize)
assert.Contains(t, err.Error(), "Unsupported scheme requested")
assert.Contains(t, err.Error(), "Do not understand the destination scheme: some. Permitted values are file, osdf, pelican, stash, ")
})
}
1 change: 0 additions & 1 deletion client/handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ var (

loader = ttlcache.LoaderFunc[string, cacheItem](
func(c *ttlcache.Cache[string, cacheItem], key string) *ttlcache.Item[string, cacheItem] {
log.Errorf("Cache miss: %v+", key)
ctx := context.Background()
// Note: setting this timeout mostly for unit tests
ctx, cancel := context.WithTimeout(ctx, param.Transport_ResponseHeaderTimeout.GetDuration())
Expand Down
10 changes: 9 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ func TestInitServerUrl(t *testing.T) {
}
func TestDiscoverUrlFederation(t *testing.T) {
t.Run("TestMetadataDiscoveryTimeout", func(t *testing.T) {
viper.Set("tlsskipverify", true)
err := InitClient()
assert.NoError(t, err)
// Create a server that sleeps for a longer duration than the timeout
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(2 * time.Second)
Expand All @@ -535,11 +538,12 @@ func TestDiscoverUrlFederation(t *testing.T) {
defer cancel()

// Call the function with the server URL and the context
_, err := DiscoverUrlFederation(ctx, server.URL)
_, err = DiscoverUrlFederation(ctx, server.URL)

// Assert that the error is the expected metadata timeout error
assert.Error(t, err)
assert.True(t, errors.Is(err, MetadataTimeoutErr))
viper.Reset()
})

t.Run("TestCanceledContext", func(t *testing.T) {
Expand All @@ -562,6 +566,9 @@ func TestDiscoverUrlFederation(t *testing.T) {
})

t.Run("TestValidDiscovery", func(t *testing.T) {
viper.Set("tlsskipverify", true)
err := InitClient()
assert.NoError(t, err)
// Server to be a "mock" federation
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// make our response:
Expand Down Expand Up @@ -594,5 +601,6 @@ func TestDiscoverUrlFederation(t *testing.T) {
assert.Equal(t, "registry", metadata.NamespaceRegistrationEndpoint, "Unexpected NamespaceRegistrationEndpoint")
assert.Equal(t, "jwks", metadata.JwksUri, "Unexpected JwksUri")
assert.Equal(t, "broker", metadata.BrokerEndpoint, "Unexpected BrokerEndpoint")
viper.Reset()
})
}
2 changes: 1 addition & 1 deletion local_cache/local_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func (sc *LocalCache) runMux() error {
sourceURL := *sc.directorURL
sourceURL.Path = path.Join(sourceURL.Path, path.Clean(req.request.path))
sourceURL.Scheme = "pelican"
tj, err := sc.tc.NewTransferJob(&sourceURL, localPath, false, false, "localcache", client.WithToken(req.request.token))
tj, err := sc.tc.NewTransferJob(&sourceURL, localPath, sc.te, false, false, "localcache", client.WithToken(req.request.token))
if err != nil {
ds := &downloadStatus{}
ds.err.Store(&err)
Expand Down

0 comments on commit 5ce04d5

Please sign in to comment.