@@ -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 ()
0 commit comments