Skip to content

Commit

Permalink
testregistry: move rootLayer to testregistry and export
Browse files Browse the repository at this point in the history
Move the root layer const to the test registry so it can be reused for
testing.  Add a comment describing what it represents and how it can be
used.
  • Loading branch information
achilleas-k authored and supakeen committed Sep 18, 2024
1 parent b815c18 commit 3f2e0f4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
8 changes: 1 addition & 7 deletions cmd/otk-resolve-containers/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ import (
resolver "github.com/osbuild/images/cmd/otk-resolve-containers"
)

const rootLayer = `H4sIAAAJbogA/+SWUYqDMBCG53lP4V5g9x8dzRX2Bvtc0VIhEIhKe/wSKxgU6ktjC/O9hMzAQDL8
/8yltdb9DLeB0gEGKhHCg/UJsBAL54zKFBAC54ZzyrCUSMfYDydPgHfu6R/s5VePilOfzF/of/bv
vG2+lqhyFNGPddP53yjyegCBKcuNROZ77AmBoP+CmbIyqpEM5fqf+3/ubJtsCuz7P1b+L1Du/4f5
v+vrsVPu/Vq9P3ANk//d+x/MZv8TKNf/Qfqf9v9v5fLXK3/lKEc5ypm4AwAA//8DAE6E6nIAEgAA
`

const (
owner = "osbuild"
reponame = "testcontainer"
Expand All @@ -39,7 +33,7 @@ func createTestRegistry() (*testregistry.Registry, []string) {
refs := make([]string, 10)
for idx := 0; idx < len(refs); idx++ {
checksum := repo.AddImage(
[]testregistry.Blob{testregistry.NewDataBlobFromBase64(rootLayer)},
[]testregistry.Blob{testregistry.NewDataBlobFromBase64(testregistry.RootLayer)},
[]string{"amd64", "ppc64le"},
fmt.Sprintf("image %d", idx),
time.Time{})
Expand Down
16 changes: 16 additions & 0 deletions internal/testregistry/testregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ import (
"github.com/osbuild/images/pkg/container"
)

/*
A base64 encoded gzipped tarball with the following contents:
-rw-r--r-- root/root 12 2021-09-17 12:32 hello.txt (Contents: "Hello World")
drwxr-xr-x root/root 0 1970-01-01 01:00 subdir/
-rw-r--r-- root/root 8 2021-09-17 12:32 subdir/file.txt (Contents: "osbuild")
-rw-r--r-- root/root 7 2021-09-17 12:32 world.txt (Contents: "hello!")
Can be used with [NewDataBlobFromBase64] to create a data blob for [Repo.AddImage].
*/
const RootLayer = `H4sIAAAJbogA/+SWUYqDMBCG53lP4V5g9x8dzRX2Bvtc0VIhEIhKe/wSKxgU6ktjC/O9hMzAQDL8
/8yltdb9DLeB0gEGKhHCg/UJsBAL54zKFBAC54ZzyrCUSMfYDydPgHfu6R/s5VePilOfzF/of/bv
vG2+lqhyFNGPddP53yjyegCBKcuNROZ77AmBoP+CmbIyqpEM5fqf+3/ubJtsCuz7P1b+L1Du/4f5
v+vrsVPu/Vq9P3ANk//d+x/MZv8TKNf/Qfqf9v9v5fLXK3/lKEc5ypm4AwAA//8DAE6E6nIAEgAA
`

// The following code implements a toy container registry to test with

// Blob interface
Expand Down
2 changes: 1 addition & 1 deletion pkg/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestClientResolve(t *testing.T) {

repo := registry.AddRepo("library/osbuild")
listDigest := repo.AddImage(
[]testregistry.Blob{testregistry.NewDataBlobFromBase64(rootLayer)},
[]testregistry.Blob{testregistry.NewDataBlobFromBase64(testregistry.RootLayer)},
[]string{"amd64", "ppc64le"},
"cool container",
time.Time{})
Expand Down
8 changes: 1 addition & 7 deletions pkg/container/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ import (
"github.com/osbuild/images/pkg/container"
)

const rootLayer = `H4sIAAAJbogA/+SWUYqDMBCG53lP4V5g9x8dzRX2Bvtc0VIhEIhKe/wSKxgU6ktjC/O9hMzAQDL8
/8yltdb9DLeB0gEGKhHCg/UJsBAL54zKFBAC54ZzyrCUSMfYDydPgHfu6R/s5VePilOfzF/of/bv
vG2+lqhyFNGPddP53yjyegCBKcuNROZ77AmBoP+CmbIyqpEM5fqf+3/ubJtsCuz7P1b+L1Du/4f5
v+vrsVPu/Vq9P3ANk//d+x/MZv8TKNf/Qfqf9v9v5fLXK3/lKEc5ypm4AwAA//8DAE6E6nIAEgAA
`

var forceLocal = flag.Bool(
"force-local-resolver",
false,
Expand All @@ -39,7 +33,7 @@ func TestResolver(t *testing.T) {
refs := make([]string, 10)
for i := 0; i < len(refs); i++ {
checksum := repo.AddImage(
[]testregistry.Blob{testregistry.NewDataBlobFromBase64(rootLayer)},
[]testregistry.Blob{testregistry.NewDataBlobFromBase64(testregistry.RootLayer)},
[]string{"amd64", "ppc64le"},
fmt.Sprintf("image %d", i),
time.Time{})
Expand Down

0 comments on commit 3f2e0f4

Please sign in to comment.