1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// Copyright (c) 2020, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package pull
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"path"
"path/filepath"
"testing"
"github.com/sylabs/singularity/v4/e2e/internal/e2e"
)
// If a remote is set to a different endpoint we should be able to pull
// with `--library https://library.sylabs.io` from the default Sylabs cloud library.
func (c ctx) issue5808(t *testing.T) {
testEndpoint := "issue5808"
testEndpointURI := "https://cloud.staging.sylabs.io"
defaultLibraryURI := "https://library.sylabs.io"
testImage := "library://sylabs/tests/signed:1.0.0"
pullDir, cleanup := e2e.MakeTempDir(t, "", "issue5808", "")
defer cleanup(t)
// Add another endpoint
argv := []string{"add", "--no-login", testEndpoint, testEndpointURI}
c.env.RunSingularity(
t,
e2e.AsSubtest("remote add"),
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("remote"),
e2e.WithArgs(argv...),
e2e.ExpectExit(0),
)
// Remove test remote when we are done here
defer func(t *testing.T) {
argv := []string{"remove", testEndpoint}
c.env.RunSingularity(
t,
e2e.AsSubtest("remote remove"),
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("remote"),
e2e.WithArgs(argv...),
e2e.ExpectExit(0),
)
}(t)
// Set as default
argv = []string{"use", testEndpoint}
c.env.RunSingularity(
t,
e2e.AsSubtest("remote use"),
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("remote"),
e2e.WithArgs(argv...),
e2e.ExpectExit(0),
)
// Pull a library image
dest := path.Join(pullDir, "alpine.sif")
argv = []string{"--arch", "amd64", "--library", defaultLibraryURI, dest, testImage}
c.env.RunSingularity(
t,
e2e.AsSubtest("pull"),
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("pull"),
e2e.WithArgs(argv...),
e2e.ExpectExit(0),
)
}
// Must be able to pull from an http(s) source that doesn't set content-length correctly
func (c ctx) issue1087(t *testing.T) {
e2e.EnsureImage(t, c.env)
tmpDir, cleanup := e2e.MakeTempDir(t, c.env.TestDir, "issue-1087-", "")
defer cleanup(t)
pullPath := filepath.Join(tmpDir, "test.sif")
// Start an http server that serves some output without a content-length
data := "DATADATADATADATA"
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprint(w, data)
}))
defer srv.Close()
c.env.RunSingularity(
t,
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("pull"),
e2e.WithArgs(pullPath, srv.URL),
e2e.ExpectExit(0),
)
content, err := os.ReadFile(pullPath)
if err != nil {
t.Error(err)
}
if string(content) != data {
t.Errorf("Content of file not correct. Expected %s, got %s", data, content)
}
}
|