-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_test.go
193 lines (184 loc) · 4.7 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package stereoscope
import (
"testing"
"github.com/scylladb/go-set/i8set"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/nextlinux/stereoscope/pkg/image"
)
func Test_setPlatform(t *testing.T) {
expectedSources := i8set.New()
for _, s := range image.AllSources {
expectedSources.Add(int8(s))
}
actualSources := i8set.New()
tests := []struct {
name string
source image.Source
defaultArch string
initialPlatform *image.Platform
wantPlatform *image.Platform
wantErr require.ErrorAssertionFunc
}{
// allow defaults ---------------------------------------------------------
{
name: "docker daemon",
source: image.DockerDaemonSource,
defaultArch: "amd64",
initialPlatform: nil,
wantPlatform: &image.Platform{
Architecture: "amd64",
OS: "linux",
},
},
{
name: "docker daemon (do not override)",
source: image.DockerDaemonSource,
defaultArch: "amd64",
initialPlatform: &image.Platform{
Architecture: "arm64", // not different than default arch
OS: "linux",
},
wantPlatform: &image.Platform{
Architecture: "arm64", // note: did not change
OS: "linux",
},
},
{
name: "podman daemon",
source: image.PodmanDaemonSource,
defaultArch: "amd64",
initialPlatform: nil,
wantPlatform: &image.Platform{
Architecture: "amd64",
OS: "linux",
},
},
{
name: "podman daemon (do not override)",
source: image.PodmanDaemonSource,
defaultArch: "amd64",
initialPlatform: &image.Platform{
Architecture: "arm64", // not different than default arch
OS: "linux",
},
wantPlatform: &image.Platform{
Architecture: "arm64", // note: did not change
OS: "linux",
},
},
{
name: "OCI registry",
source: image.OciRegistrySource,
defaultArch: "amd64",
initialPlatform: nil,
wantPlatform: &image.Platform{
Architecture: "amd64",
OS: "linux",
},
},
{
name: "OCI registry (do not override)",
source: image.OciRegistrySource,
defaultArch: "amd64",
initialPlatform: &image.Platform{
Architecture: "arm64", // not different than default arch
OS: "linux",
},
wantPlatform: &image.Platform{
Architecture: "arm64", // note: did not change
OS: "linux",
},
},
// disallow defaults ---------------------------------------------------------
{
name: "docker tarball",
source: image.DockerTarballSource,
defaultArch: "amd64",
initialPlatform: nil,
wantPlatform: nil,
},
{
name: "docker tarball (override fails)",
source: image.DockerTarballSource,
defaultArch: "amd64",
initialPlatform: &image.Platform{
Architecture: "amd64",
OS: "linux",
},
wantErr: require.Error,
},
{
name: "OCI dir",
source: image.OciDirectorySource,
defaultArch: "amd64",
initialPlatform: nil,
wantPlatform: nil,
},
{
name: "OCI dir (override fails)",
source: image.OciDirectorySource,
defaultArch: "amd64",
initialPlatform: &image.Platform{
Architecture: "amd64",
OS: "linux",
},
wantErr: require.Error,
},
{
name: "OCI tarball",
source: image.OciTarballSource,
defaultArch: "amd64",
initialPlatform: nil,
wantPlatform: nil,
},
{
name: "OCI tarball (override fails)",
source: image.OciTarballSource,
defaultArch: "amd64",
initialPlatform: &image.Platform{
Architecture: "amd64",
OS: "linux",
},
wantErr: require.Error,
},
{
name: "singularity",
source: image.SingularitySource,
defaultArch: "amd64",
initialPlatform: nil,
wantPlatform: nil,
},
{
name: "singularity (override fails)",
source: image.SingularitySource,
defaultArch: "amd64",
initialPlatform: &image.Platform{
Architecture: "amd64",
OS: "linux",
},
wantErr: require.Error,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.wantErr == nil {
tt.wantErr = require.NoError
}
actualSources.Add(int8(tt.source))
cfg := config{
Platform: tt.initialPlatform,
}
err := setPlatform(tt.source, &cfg, tt.defaultArch)
tt.wantErr(t, err)
if err != nil {
return
}
assert.Equal(t, tt.wantPlatform, cfg.Platform)
})
}
diff := i8set.Difference(expectedSources, actualSources)
if !diff.IsEmpty() {
t.Errorf("missing test cases for sources: %v", diff.List())
}
}