@@ -63,6 +63,98 @@ func TestDocker(t *testing.T) {
63
63
execer .AssertCommandsCalled (t )
64
64
})
65
65
66
+ t .Run ("Images" , func (t * testing.T ) {
67
+ t .Parallel ()
68
+
69
+ type testcase struct {
70
+ name string
71
+ image string
72
+ success bool
73
+ }
74
+
75
+ testcases := []testcase {
76
+ {
77
+ name : "Repository" ,
78
+ image : "ubuntu" ,
79
+ success : true ,
80
+ },
81
+ {
82
+ name : "RepositoryPath" ,
83
+ image : "ubuntu/ubuntu" ,
84
+ success : true ,
85
+ },
86
+
87
+ {
88
+ name : "RepositoryLatest" ,
89
+ image : "ubuntu:latest" ,
90
+ success : true ,
91
+ },
92
+ {
93
+ name : "RepositoryTag" ,
94
+ image : "ubuntu:24.04" ,
95
+ success : true ,
96
+ },
97
+ {
98
+ name : "RepositoryPathTag" ,
99
+ image : "ubuntu/ubuntu:18.04" ,
100
+ success : true ,
101
+ },
102
+ {
103
+ name : "RegistryRepository" ,
104
+ image : "gcr.io/ubuntu" ,
105
+ success : true ,
106
+ },
107
+ {
108
+ name : "RegistryRepositoryTag" ,
109
+ image : "gcr.io/ubuntu:24.04" ,
110
+ success : true ,
111
+ },
112
+ }
113
+
114
+ for _ , tc := range testcases {
115
+ tc := tc
116
+ t .Run (tc .name , func (t * testing.T ) {
117
+ t .Parallel ()
118
+
119
+ ctx , cmd := clitest .New (t , "docker" ,
120
+ "--image=" + tc .image ,
121
+ "--username=root" ,
122
+ "--agent-token=hi" ,
123
+ )
124
+
125
+ called := make (chan struct {})
126
+ execer := clitest .Execer (ctx )
127
+ client := clitest .DockerClient (t , ctx )
128
+ execer .AddCommands (& xunixfake.FakeCmd {
129
+ FakeCmd : & testingexec.FakeCmd {
130
+ Argv : []string {
131
+ "sysbox-mgr" ,
132
+ },
133
+ },
134
+ WaitFn : func () error { close (called ); select {} }, //nolint:revive
135
+ })
136
+
137
+ var created bool
138
+ client .ContainerCreateFn = func (_ context.Context , conf * container.Config , _ * container.HostConfig , _ * network.NetworkingConfig , _ * v1.Platform , _ string ) (container.CreateResponse , error ) {
139
+ created = true
140
+ require .Equal (t , tc .image , conf .Image )
141
+ return container.CreateResponse {}, nil
142
+ }
143
+
144
+ err := cmd .ExecuteContext (ctx )
145
+ if ! tc .success {
146
+ require .Error (t , err )
147
+ return
148
+ }
149
+
150
+ <- called
151
+ require .NoError (t , err )
152
+ require .True (t , created , "container create fn not called" )
153
+ execer .AssertCommandsCalled (t )
154
+ })
155
+ }
156
+ })
157
+
66
158
// Test that dockerd is configured correctly.
67
159
t .Run ("DockerdConfigured" , func (t * testing.T ) {
68
160
t .Parallel ()
@@ -384,13 +476,13 @@ func TestDocker(t *testing.T) {
384
476
t .Parallel ()
385
477
386
478
ctx , cmd := clitest .New (t , "docker" ,
387
- "--image=ubuntu" ,
479
+ "--image=us.gcr.io/ ubuntu" ,
388
480
"--username=root" ,
389
481
"--agent-token=hi" ,
390
482
fmt .Sprintf ("--image-secret=%s" , rawDockerAuth ),
391
483
)
392
484
393
- raw := []
byte (
`{"username":"_json_key","password":"{\"type\": \"service_account\", \"project_id\": \"some-test\", \"private_key_id\": \"blahblah\", \"private_key\": \"-----BEGIN PRIVATE KEY-----mykey-----END PRIVATE KEY-----\", \"client_email\": \"[email protected] \", \"client_id\": \"123\", \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\", \"token_uri\": \"https://oauth2.googleapis.com/token\", \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\", \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/test.iam.gserviceaccount.com\" }","auth":"X2pzb25fa2V5OnsKCgkidHlwZSI6ICJzZXJ2aWNlX2FjY291bnQiLAoJInByb2plY3RfaWQiOiAic29tZS10ZXN0IiwKCSJwcml2YXRlX2tleV9pZCI6ICJibGFoYmxhaCIsCgkicHJpdmF0ZV9rZXkiOiAiLS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCm15a2V5LS0tLS1FTkQgUFJJVkFURSBLRVktLS0tLQoiLAoJImNsaWVudF9lbWFpbCI6ICJ0ZXN0QHRlc3QuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20iLAoJImNsaWVudF9pZCI6ICIxMjMiLAoJImF1dGhfdXJpIjogImh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi9hdXRoIiwKCSJ0b2tlbl91cmkiOiAiaHR0cHM6Ly9vYXV0aDIuZ29vZ2xlYXBpcy5jb20vdG9rZW4iLAoJImF1dGhfcHJvdmlkZXJfeDUwOV9jZXJ0X3VybCI6ICJodHRwczovL3d3dy5nb29nbGVhcGlzLmNvbS9vYXV0aDIvdjEvY2VydHMiLAoJImNsaWVudF94NTA5X2NlcnRfdXJsIjogImh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL3JvYm90L3YxL21ldGFkYXRhL3g1MDkvdGVzdC5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIKfQo=","email":"[email protected] "}` )
485
+ raw := []
byte (
`{"username":"_json_key","password":"{\"type\": \"service_account\", \"project_id\": \"some-test\", \"private_key_id\": \"blahblah\", \"private_key\": \"-----BEGIN PRIVATE KEY-----mykey-----END PRIVATE KEY-----\", \"client_email\": \"[email protected] \", \"client_id\": \"123\", \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\", \"token_uri\": \"https://oauth2.googleapis.com/token\", \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\", \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/test.iam.gserviceaccount.com\" }"}` )
394
486
authB64 := base64 .URLEncoding .EncodeToString (raw )
395
487
396
488
client := clitest .DockerClient (t , ctx )
0 commit comments