Skip to content

Commit

Permalink
pkg/container: move test registry implementation out of tests
Browse files Browse the repository at this point in the history
Move the toy implementation of a container registry out of the
container_test package and into internal/testregistry so it can be
reused across subpackages of the repository.
  • Loading branch information
achilleas-k authored and supakeen committed Sep 18, 2024
1 parent 6f7dd27 commit fd5811e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package container_test
package testregistry

import (
"bytes"
Expand All @@ -22,12 +22,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
`

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

// Blob interface
Expand Down Expand Up @@ -289,7 +283,7 @@ func (reg *Registry) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
}

func NewTestRegistry() *Registry {
func New() *Registry {

reg := &Registry{
repos: make(map[string]*Repo),
Expand Down
5 changes: 3 additions & 2 deletions pkg/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/osbuild/images/internal/testregistry"
"github.com/osbuild/images/pkg/arch"
"github.com/osbuild/images/pkg/container"
)
Expand All @@ -16,12 +17,12 @@ import (

func TestClientResolve(t *testing.T) {

registry := NewTestRegistry()
registry := testregistry.New()
defer registry.Close()

repo := registry.AddRepo("library/osbuild")
listDigest := repo.AddImage(
[]Blob{NewDataBlobFromBase64(rootLayer)},
[]testregistry.Blob{testregistry.NewDataBlobFromBase64(rootLayer)},
[]string{"amd64", "ppc64le"},
"cool container",
time.Time{})
Expand Down
13 changes: 10 additions & 3 deletions pkg/container/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ import (
"github.com/stretchr/testify/assert"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/testregistry"
"github.com/osbuild/images/pkg/arch"
"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 @@ -24,15 +31,15 @@ var forceLocal = flag.Bool(

func TestResolver(t *testing.T) {

registry := NewTestRegistry()
registry := testregistry.New()
defer registry.Close()
repo := registry.AddRepo("library/osbuild")
ref := registry.GetRef("library/osbuild")

refs := make([]string, 10)
for i := 0; i < len(refs); i++ {
checksum := repo.AddImage(
[]Blob{NewDataBlobFromBase64(rootLayer)},
[]testregistry.Blob{testregistry.NewDataBlobFromBase64(rootLayer)},
[]string{"amd64", "ppc64le"},
fmt.Sprintf("image %d", i),
time.Time{})
Expand Down Expand Up @@ -84,7 +91,7 @@ func TestResolverFail(t *testing.T) {
assert.Error(t, err)
assert.Len(t, specs, 0)

registry := NewTestRegistry()
registry := testregistry.New()
defer registry.Close()

resolver.Add(container.SourceSpec{
Expand Down

0 comments on commit fd5811e

Please sign in to comment.