Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conformance: skip check (by default) for zero layers in image manifest #421

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions conformance/02_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var test02Push = func() {
g.Context(titlePush, func() {

var lastResponse, prevResponse *reggie.Response
var emptyLayerManifestRef string

g.Context("Setup", func() {
// No setup required at this time for push tests
Expand Down Expand Up @@ -350,16 +351,20 @@ var test02Push = func() {

g.Specify("Registry should accept a manifest upload with no layers", func() {
SkipIfDisabled(push)
RunOnlyIfNot(skipEmptyLayerTest)
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>",
reggie.WithReference(emptyLayerTestTag)).
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
SetBody(emptyLayerManifestContent)
resp, err := client.Do(req)
Expect(err).To(BeNil())
location := resp.Header().Get("Location")
Expect(location).ToNot(BeEmpty())
Expect(resp.StatusCode()).To(Equal(http.StatusCreated))
if resp.StatusCode() == http.StatusCreated {
location := resp.Header().Get("Location")
emptyLayerManifestRef = location
Expect(location).ToNot(BeEmpty())
Expect(resp.StatusCode()).To(Equal(http.StatusCreated))
} else {
Warn("image manifest with no layers is not supported")
}
})

g.Specify("GET request to manifest URL (digest) should yield 200 response", func() {
Expand Down Expand Up @@ -387,6 +392,18 @@ var test02Push = func() {
),
Equal(http.StatusMethodNotAllowed),
))
if emptyLayerManifestRef != "" {
req = client.NewRequest(reggie.DELETE, emptyLayerManifestRef)
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
}
})
}

Expand Down Expand Up @@ -434,6 +451,18 @@ var test02Push = func() {
),
Equal(http.StatusMethodNotAllowed),
))
if emptyLayerManifestRef != "" {
req = client.NewRequest(reggie.DELETE, emptyLayerManifestRef)
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
}
})
}
})
Expand Down
13 changes: 10 additions & 3 deletions conformance/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"math/big"
mathrand "math/rand"
"os"
"runtime"
"strconv"

"github.com/bloodorangeio/reggie"
"github.com/google/uuid"
g "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/formatter"
godigest "github.com/opencontainers/go-digest"
)

Expand Down Expand Up @@ -128,7 +130,6 @@ var (
runPushSetup bool
runContentDiscoverySetup bool
runContentManagementSetup bool
skipEmptyLayerTest bool
deleteManifestBeforeBlobs bool
runAutomaticCrossmountTest bool
automaticCrossmountEnabled bool
Expand Down Expand Up @@ -309,7 +310,6 @@ func init() {
runPushSetup = true
runContentDiscoverySetup = true
runContentManagementSetup = true
skipEmptyLayerTest = false
deleteManifestBeforeBlobs = true

if os.Getenv(envVarTagName) != "" &&
Expand All @@ -322,7 +322,6 @@ func init() {
runContentDiscoverySetup = false
}

skipEmptyLayerTest, _ = strconv.ParseBool(os.Getenv(envVarPushEmptyLayer))
if v, ok := os.LookupEnv(envVarDeleteManifestBeforeBlobs); ok {
deleteManifestBeforeBlobs, _ = strconv.ParseBool(v)
}
jdolitsky marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -354,6 +353,14 @@ func RunOnlyIfNot(v bool) {
}
}

func Warn(message string) {
// print message
fmt.Fprint(os.Stderr, formatter.Fi(2, "\n{{magenta}}WARNING: %s\n{{/}}", message))
// print file:line
_, file, line, _ := runtime.Caller(1)
fmt.Fprint(os.Stderr, formatter.Fi(2, "\n%s:%d\n", file, line))
}

func generateSkipReport() string {
buf := new(bytes.Buffer)
fmt.Fprintf(buf, "you have skipped this test; if this is an error, check your environment variable settings:\n")
Expand Down