Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7de5814a26 | ||
|
|
dfdfd84efe | ||
|
|
2bc9ea9377 |
@@ -0,0 +1,74 @@
|
||||
// Package publishconformance holds the cases every holder of a registry seat's `publish` is held to, so that two holders of
|
||||
// one contract cannot each read it their own way (novox/hq design 47 G A-73, A-417, A-490): a publish with a version, a
|
||||
// digest and no parts is the builder's publish again. A holder holding what the digest names under the name says it published
|
||||
// (it moves nothing, or, where the bytes sit in the artifact store, as distribution's A-417 takes them, tags them); a holder
|
||||
// that holds none of it, or holds the version under another digest, refuses it as not stored, naming the digest, and says it
|
||||
// refused (A-490, A-490a). The cases live here beside the build modules' conformance kit (design 47 G §680, A-490a). A
|
||||
// holder's own test runs Run over its own test bed, for every seat it fills.
|
||||
package publishconformance
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Name, Version and Digest are what the cases publish.
|
||||
const (
|
||||
Name = "novox/example"
|
||||
Version = "0.1.0"
|
||||
Digest = "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
||||
// Other is a digest the holder holds under the version in the case where it holds another; it does not contain Digest.
|
||||
Other = "sha256:fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210"
|
||||
)
|
||||
|
||||
// Outcome is what a holder did with a publish: whether the transfer ended with it, how many parts it asked for, the event
|
||||
// it said on its seat (published or refused) with its reason, and the error it answered.
|
||||
type Outcome struct {
|
||||
Ended bool
|
||||
Lacks int
|
||||
Event string
|
||||
Reason string
|
||||
Err error
|
||||
}
|
||||
|
||||
// Bed is one holder under test, fresh for a case.
|
||||
type Bed struct {
|
||||
// Hold makes the holder hold the digest under Name at Version, as the builder's reservation of Version would find it.
|
||||
Hold func(digest string)
|
||||
// Publish sends the publish of name at version with the digest and no parts, and reports what the holder did.
|
||||
Publish func(name, version, digest string) Outcome
|
||||
}
|
||||
|
||||
// Run runs the cases over beds made by fresh.
|
||||
func Run(t *testing.T, fresh func(t *testing.T) Bed) {
|
||||
t.Helper()
|
||||
t.Run("a publish with a digest and no parts is published when the holder holds it", func(t *testing.T) {
|
||||
b := fresh(t)
|
||||
b.Hold(Digest)
|
||||
o := b.Publish(Name, Version, Digest)
|
||||
if o.Err != nil || !o.Ended || o.Lacks != 0 || o.Event != "published" {
|
||||
t.Fatalf("a held digest answered %+v; want ended, no part lacked, published said", o)
|
||||
}
|
||||
})
|
||||
t.Run("a publish with a digest and no parts is refused as not stored, naming the digest, when the holder holds none", func(t *testing.T) {
|
||||
b := fresh(t)
|
||||
o := b.Publish(Name, Version, Digest)
|
||||
if o.Err == nil || !strings.Contains(o.Err.Error(), "not stored") || !strings.Contains(o.Err.Error(), Digest) {
|
||||
t.Fatalf("a digest not held answered %+v; want the error to say not stored and name %s", o, Digest)
|
||||
}
|
||||
if o.Event != "refused" || !strings.Contains(o.Reason, "not stored") || !strings.Contains(o.Reason, Digest) || o.Lacks != 0 || !o.Ended {
|
||||
t.Errorf("a digest not held answered %+v; want refused said with the digest in its reason, ended, no part lacked", o)
|
||||
}
|
||||
})
|
||||
t.Run("a publish with a digest and no parts is refused as not stored, naming the digest, when the holder holds the version under another digest", func(t *testing.T) {
|
||||
b := fresh(t)
|
||||
b.Hold(Other)
|
||||
o := b.Publish(Name, Version, Digest)
|
||||
if o.Err == nil || !strings.Contains(o.Err.Error(), "not stored") || !strings.Contains(o.Err.Error(), Digest) {
|
||||
t.Fatalf("another digest held answered %+v; want the error to say not stored and name %s", o, Digest)
|
||||
}
|
||||
if o.Event != "refused" || !strings.Contains(o.Reason, "not stored") || !strings.Contains(o.Reason, Digest) || o.Lacks != 0 || !o.Ended {
|
||||
t.Errorf("another digest held answered %+v; want refused said as not stored with the digest, ended, no part lacked", o)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user