Skip to content

Commit 6a842e3

Browse files
achilleas-ksupakeen
authored andcommitted
cmd/otk-resolve-containers: add raw JSON test
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.
1 parent 3f2e0f4 commit 6a842e3

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

cmd/otk-resolve-containers/main_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,67 @@ func TestResolverUnhappy(t *testing.T) {
185185
})
186186
}
187187
}
188+
189+
func TestResolverRawJSON(t *testing.T) {
190+
require := require.New(t)
191+
192+
registry, refs := createTestRegistry()
193+
defer registry.Close()
194+
195+
inpContainers := make([]blueprint.Container, len(refs))
196+
for idx, ref := range refs {
197+
inpContainers[idx] = blueprint.Container{
198+
Source: ref,
199+
Name: fmt.Sprintf("test/localhost/%s", ref), // add a prefix for the local name to override the source
200+
TLSVerify: common.ToPtr(false),
201+
LocalStorage: false,
202+
}
203+
}
204+
205+
for _, containerArch := range []string{"amd64", "ppc64le"} {
206+
t.Run(containerArch, func(t *testing.T) {
207+
cntName := fmt.Sprintf("test/localhost/%s", refs[0])
208+
inpBuf := bytes.NewBufferString(fmt.Sprintf(`{
209+
"tree":{
210+
"arch":"%s",
211+
"containers":[
212+
{
213+
"source":"%s",
214+
"name":"%s",
215+
"tls-verify":false
216+
}
217+
]
218+
}
219+
}`, containerArch, refs[0], cntName))
220+
outBuf := &bytes.Buffer{}
221+
222+
err := resolver.Run(inpBuf, outBuf)
223+
require.NoError(err)
224+
225+
// resolve directly with the registry and convert to a raw JSON
226+
// string to compare with output
227+
spec, err := registry.Resolve(refs[0], arch.FromString(containerArch))
228+
require.NoError(err)
229+
230+
expected := fmt.Sprintf(`{
231+
"tree": {
232+
"const": {
233+
"containers": [
234+
{
235+
"source": "%s",
236+
"digest": "%s",
237+
"imageid": "%s",
238+
"local-name": "%s",
239+
"list-digest": "%s",
240+
"arch": "%s",
241+
"tls-verify": %v
242+
}
243+
]
244+
}
245+
}
246+
}
247+
`, spec.Source, spec.Digest, spec.ImageID, fmt.Sprintf("test/localhost/%s", refs[0]), spec.ListDigest, spec.Arch, *spec.TLSVerify)
248+
require.Equal(expected, outBuf.String())
249+
})
250+
}
251+
}

0 commit comments

Comments
 (0)