Split the unit level from the integration level outside cmd, builder, link, catalogue, inventory; merge-check.sh times and bounds the unit level (issue 895)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
//go:build integration
|
||||
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//go:build integration
|
||||
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestLiveADocumentPutUnderATagIsReadBackAndOnlyTheNewestIsKept(t *testing.T) {
|
||||
address := os.Getenv("MESH_TEST_REGISTRY")
|
||||
container := os.Getenv("MESH_TEST_REGISTRY_CONTAINER")
|
||||
if address == "" || container == "" {
|
||||
t.Skip("no MESH_TEST_REGISTRY / MESH_TEST_REGISTRY_CONTAINER; see the collector test's comment for the registry to raise")
|
||||
}
|
||||
ctx := context.Background()
|
||||
store := Store{Address: address}
|
||||
repository := fmt.Sprintf("facts-live-%d", time.Now().UnixNano())
|
||||
|
||||
if _, _, err := store.GetTagged(ctx, repository, "latest"); !errors.Is(err, ErrNoTag) {
|
||||
t.Fatalf("nothing was put and the read said %v, not that nothing is there", err)
|
||||
}
|
||||
first := []byte(`{"facts":1,"taken":"first"}`)
|
||||
firstDigest, err := store.PutTagged(ctx, repository, "latest", "application/vnd.novox.mesh.facts.v1+json", first)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second := []byte(`{"facts":1,"taken":"second"}`)
|
||||
secondDigest, err := store.PutTagged(ctx, repository, "latest", "application/vnd.novox.mesh.facts.v1+json", second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, digest, err := store.GetTagged(ctx, repository, "latest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(got) != string(second) || digest != secondDigest {
|
||||
t.Fatalf("read back %q (%s), not the newest put %q (%s)", got, digest, second, secondDigest)
|
||||
}
|
||||
|
||||
// The collector, as the store's nightly step runs it — with no `--delete-untagged`: the newest kept,
|
||||
// the replaced one taken because its manifest was let go of.
|
||||
out, err := exec.Command("docker", "exec", container, "registry", "garbage-collect",
|
||||
"/etc/docker/registry/config.yml").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("the collector did not run: %v\n%s", err, out)
|
||||
}
|
||||
if got, _, err := store.GetTagged(ctx, repository, "latest"); err != nil || string(got) != string(second) {
|
||||
t.Fatalf("after collection the newest reads %q, %v", got, err)
|
||||
}
|
||||
// On the store's disk, not as the running server answers: it caches blob descriptors in memory.
|
||||
onDisk := func(digest string) bool {
|
||||
hex := strings.TrimPrefix(digest, "sha256:")
|
||||
path := "/var/lib/registry/docker/registry/v2/blobs/sha256/" + hex[:2] + "/" + hex + "/data"
|
||||
return exec.Command("docker", "exec", container, "test", "-f", path).Run() == nil
|
||||
}
|
||||
if onDisk(firstDigest) {
|
||||
t.Errorf("the replaced snapshot %s is still in the store after collection; nothing would ever take it", firstDigest)
|
||||
}
|
||||
if !onDisk(secondDigest) {
|
||||
t.Errorf("the collector took the newest snapshot %s", secondDigest)
|
||||
}
|
||||
if !strings.HasPrefix(secondDigest, "sha256:") {
|
||||
t.Errorf("the digest said %q", secondDigest)
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,8 @@ package artifacts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The facts snapshot is put under a tag and read back by it (novox/hq to-be 45 §9).
|
||||
@@ -17,63 +12,6 @@ import (
|
||||
// that a manifest put by tag is read by tag, that the layer comes back whole and checked, and that the
|
||||
// snapshot a newer one replaced is the collector's to take while the newest is kept. Raised as the
|
||||
// collector test above says, with MESH_TEST_REGISTRY and MESH_TEST_REGISTRY_CONTAINER.
|
||||
func TestLiveADocumentPutUnderATagIsReadBackAndOnlyTheNewestIsKept(t *testing.T) {
|
||||
address := os.Getenv("MESH_TEST_REGISTRY")
|
||||
container := os.Getenv("MESH_TEST_REGISTRY_CONTAINER")
|
||||
if address == "" || container == "" {
|
||||
t.Skip("no MESH_TEST_REGISTRY / MESH_TEST_REGISTRY_CONTAINER; see the collector test's comment for the registry to raise")
|
||||
}
|
||||
ctx := context.Background()
|
||||
store := Store{Address: address}
|
||||
repository := fmt.Sprintf("facts-live-%d", time.Now().UnixNano())
|
||||
|
||||
if _, _, err := store.GetTagged(ctx, repository, "latest"); !errors.Is(err, ErrNoTag) {
|
||||
t.Fatalf("nothing was put and the read said %v, not that nothing is there", err)
|
||||
}
|
||||
first := []byte(`{"facts":1,"taken":"first"}`)
|
||||
firstDigest, err := store.PutTagged(ctx, repository, "latest", "application/vnd.novox.mesh.facts.v1+json", first)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second := []byte(`{"facts":1,"taken":"second"}`)
|
||||
secondDigest, err := store.PutTagged(ctx, repository, "latest", "application/vnd.novox.mesh.facts.v1+json", second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, digest, err := store.GetTagged(ctx, repository, "latest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(got) != string(second) || digest != secondDigest {
|
||||
t.Fatalf("read back %q (%s), not the newest put %q (%s)", got, digest, second, secondDigest)
|
||||
}
|
||||
|
||||
// The collector, as the store's nightly step runs it — with no `--delete-untagged`: the newest kept,
|
||||
// the replaced one taken because its manifest was let go of.
|
||||
out, err := exec.Command("docker", "exec", container, "registry", "garbage-collect",
|
||||
"/etc/docker/registry/config.yml").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("the collector did not run: %v\n%s", err, out)
|
||||
}
|
||||
if got, _, err := store.GetTagged(ctx, repository, "latest"); err != nil || string(got) != string(second) {
|
||||
t.Fatalf("after collection the newest reads %q, %v", got, err)
|
||||
}
|
||||
// On the store's disk, not as the running server answers: it caches blob descriptors in memory.
|
||||
onDisk := func(digest string) bool {
|
||||
hex := strings.TrimPrefix(digest, "sha256:")
|
||||
path := "/var/lib/registry/docker/registry/v2/blobs/sha256/" + hex[:2] + "/" + hex + "/data"
|
||||
return exec.Command("docker", "exec", container, "test", "-f", path).Run() == nil
|
||||
}
|
||||
if onDisk(firstDigest) {
|
||||
t.Errorf("the replaced snapshot %s is still in the store after collection; nothing would ever take it", firstDigest)
|
||||
}
|
||||
if !onDisk(secondDigest) {
|
||||
t.Errorf("the collector took the newest snapshot %s", secondDigest)
|
||||
}
|
||||
if !strings.HasPrefix(secondDigest, "sha256:") {
|
||||
t.Errorf("the digest said %q", secondDigest)
|
||||
}
|
||||
}
|
||||
|
||||
// A store with no address is said, not dialled.
|
||||
func TestADocumentWithNowhereToGoIsRefusedByName(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user