9
9
"testing"
10
10
11
11
"github.com/defenseunicorns/pkg/helpers/v2"
12
+ v1 "github.com/opencontainers/image-spec/specs-go/v1"
12
13
"github.com/stretchr/testify/require"
13
14
"github.com/zarf-dev/zarf/src/pkg/state"
14
15
"github.com/zarf-dev/zarf/src/pkg/transform"
@@ -17,7 +18,7 @@ import (
17
18
"oras.land/oras-go/v2/registry/remote"
18
19
)
19
20
20
- func populateLocalRegistry (t * testing.T , ctx context.Context , localUrl string , artifact transform.Image ) {
21
+ func populateLocalRegistry (t * testing.T , ctx context.Context , localUrl string , artifact transform.Image , copyOpts oras. CopyOptions ) {
21
22
localReg , err := remote .NewRegistry (localUrl )
22
23
require .NoError (t , err )
23
24
@@ -32,17 +33,17 @@ func populateLocalRegistry(t *testing.T, ctx context.Context, localUrl string, a
32
33
dst , err := localReg .Repository (ctx , artifact .Path )
33
34
require .NoError (t , err )
34
35
35
- _ , err = oras .Copy (ctx , src , artifact .Tag , dst , artifact .Tag , oras . DefaultCopyOptions )
36
+ _ , err = oras .Copy (ctx , src , artifact .Tag , dst , artifact .Tag , copyOpts )
36
37
require .NoError (t , err )
37
38
38
39
hashedTag , err := transform .ImageTransformHost (localUrl , fmt .Sprintf ("%s/%s:%s" , artifact .Host , artifact .Path , artifact .Tag ))
39
40
require .NoError (t , err )
40
41
41
- _ , err = oras .Copy (ctx , src , artifact .Tag , dst , hashedTag , oras . DefaultCopyOptions )
42
+ _ , err = oras .Copy (ctx , src , artifact .Tag , dst , hashedTag , copyOpts )
42
43
require .NoError (t , err )
43
44
}
44
45
45
- func setupRegistry (t * testing.T , ctx context.Context , port int , artifacts []transform.Image ) (string , error ) {
46
+ func setupRegistry (t * testing.T , ctx context.Context , port int , artifacts []transform.Image , copyOpts oras. CopyOptions ) (string , error ) {
46
47
localUrl := testutil .SetupInMemoryRegistry (ctx , t , port )
47
48
48
49
localReg , err := remote .NewRegistry (localUrl )
@@ -52,7 +53,7 @@ func setupRegistry(t *testing.T, ctx context.Context, port int, artifacts []tran
52
53
}
53
54
54
55
for _ , art := range artifacts {
55
- populateLocalRegistry (t , ctx , localUrl , art )
56
+ populateLocalRegistry (t , ctx , localUrl , art , copyOpts )
56
57
}
57
58
58
59
return localUrl , nil
@@ -63,19 +64,27 @@ type mediaTypeTest struct {
63
64
image string
64
65
expected string
65
66
artifact []transform.Image
67
+ Opts oras.CopyOptions
66
68
}
67
69
68
70
func TestConfigMediaTypes (t * testing.T ) {
69
71
t .Parallel ()
70
72
port , err := helpers .GetAvailablePort ()
71
73
require .NoError (t , err )
72
74
75
+ linuxAmd64Opts := oras .DefaultCopyOptions
76
+ linuxAmd64Opts .WithTargetPlatform (& v1.Platform {
77
+ Architecture : "amd64" ,
78
+ OS : "linux" ,
79
+ })
80
+
73
81
tests := []mediaTypeTest {
74
82
{
75
83
// https://oci.dag.dev/?image=ghcr.io%2Fstefanprodan%2Fmanifests%2Fpodinfo%3A6.9.0
76
84
name : "flux manifest" ,
77
85
expected : "application/vnd.cncf.flux.config.v1+json" ,
78
86
image : fmt .Sprintf ("localhost:%d/stefanprodan/manifests/podinfo:6.9.0-zarf-2823281104" , port ),
87
+ Opts : oras .DefaultCopyOptions ,
79
88
artifact : []transform.Image {
80
89
{
81
90
Host : "ghcr.io" ,
@@ -89,6 +98,7 @@ func TestConfigMediaTypes(t *testing.T) {
89
98
name : "helm chart manifest" ,
90
99
expected : "application/vnd.cncf.helm.config.v1+json" ,
91
100
image : fmt .Sprintf ("localhost:%d/stefanprodan/charts/podinfo:6.9.0" , port ),
101
+ Opts : oras .DefaultCopyOptions ,
92
102
artifact : []transform.Image {
93
103
{
94
104
Host : "ghcr.io" ,
@@ -98,11 +108,11 @@ func TestConfigMediaTypes(t *testing.T) {
98
108
},
99
109
},
100
110
{
101
- // docker images do not include a `.config.mediaType`
102
- // https://oci.dag.dev/?image=ghcr.io%2Fstefanprodan%2Fpodinfo%3A6.9.0
111
+ //
103
112
name : "docker image manifest" ,
104
- expected : "" ,
113
+ expected : "application/vnd.oci.image.config.v1+json " ,
105
114
image : fmt .Sprintf ("localhost:%d/zarf-dev/images/hello-world:latest" , port ),
115
+ Opts : linuxAmd64Opts ,
106
116
artifact : []transform.Image {
107
117
{
108
118
Host : "ghcr.io" ,
@@ -118,7 +128,7 @@ func TestConfigMediaTypes(t *testing.T) {
118
128
t .Run (tt .name , func (t * testing.T ) {
119
129
t .Parallel ()
120
130
ctx := testutil .TestContext (t )
121
- url , err := setupRegistry (t , ctx , port , tt .artifact )
131
+ url , err := setupRegistry (t , ctx , port , tt .artifact , tt . Opts )
122
132
require .NoError (t , err )
123
133
124
134
s := & state.State {RegistryInfo : state.RegistryInfo {Address : url }}
0 commit comments