Skip to content

Commit

Permalink
cmd/otk-resolve-containers: add raw JSON test
Browse files Browse the repository at this point in the history
Add an extra test that generates a raw json string as input and checks
the raw json string from the output.  This test resolves only one
container to make the construction of the output less tedious and avoid
the need to predict and verify the order of the results.
  • Loading branch information
achilleas-k committed Sep 18, 2024
1 parent b7c4180 commit 31d94be
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions cmd/otk-resolve-containers/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,67 @@ func TestResolverUnhappy(t *testing.T) {
})
}
}

func TestResolverRawJSON(t *testing.T) {
require := require.New(t)

registry, refs := createTestRegistry()
defer registry.Close()

inpContainers := make([]blueprint.Container, len(refs))
for idx, ref := range refs {
inpContainers[idx] = blueprint.Container{
Source: ref,
Name: fmt.Sprintf("test/localhost/%s", ref), // add a prefix for the local name to override the source
TLSVerify: common.ToPtr(false),
LocalStorage: false,
}
}

for _, containerArch := range []string{"amd64", "ppc64le"} {
t.Run(containerArch, func(t *testing.T) {
cntName := fmt.Sprintf("test/localhost/%s", refs[0])
inpBuf := bytes.NewBufferString(fmt.Sprintf(`{
"tree":{
"arch":"%s",
"containers":[
{
"source":"%s",
"name":"%s",
"tls-verify":false
}
]
}
}`, containerArch, refs[0], cntName))
outBuf := &bytes.Buffer{}

err := resolver.Run(inpBuf, outBuf)
require.NoError(err)

// resolve directly with the registry and convert to a raw JSON
// string to compare with output
spec, err := registry.Resolve(refs[0], arch.FromString(containerArch))
require.NoError(err)

expected := fmt.Sprintf(`{
"tree": {
"const": {
"containers": [
{
"source": "%s",
"digest": "%s",
"imageid": "%s",
"local-name": "%s",
"list-digest": "%s",
"arch": "%s",
"tls-verify": %v
}
]
}
}
}
`, spec.Source, spec.Digest, spec.ImageID, fmt.Sprintf("test/localhost/%s", refs[0]), spec.ListDigest, spec.Arch, *spec.TLSVerify)
require.Equal(expected, outBuf.String())
})
}
}

0 comments on commit 31d94be

Please sign in to comment.