@@ -43,6 +43,42 @@ type historyObj struct {
43
43
Comment string
44
44
}
45
45
46
+ const createdAt = "2025-02-13T19:28:36-08:00"
47
+
48
+ // Expected content of the common image on arm64
49
+ var (
50
+ createdAtTime , _ = time .Parse (time .RFC3339 , createdAt )
51
+ expectedHistory = []historyObj {
52
+ {
53
+ CreatedBy : "CMD [\" /bin/sh\" ]" ,
54
+ Size : "0B" ,
55
+ CreatedAt : createdAt ,
56
+ Snapshot : "<missing>" ,
57
+ Comment : "buildkit.dockerfile.v0" ,
58
+ CreatedSince : formatter .TimeSinceInHuman (createdAtTime ),
59
+ },
60
+ {
61
+ CreatedBy : "ADD alpine-minirootfs-3.21.3-aarch64.tar.gz …" ,
62
+ Size : "8.843MB" ,
63
+ CreatedAt : createdAt ,
64
+ Snapshot : "sha256:a16e98724c05975ee8c40d8fe389c3481373d…" ,
65
+ Comment : "buildkit.dockerfile.v0" ,
66
+ CreatedSince : formatter .TimeSinceInHuman (createdAtTime ),
67
+ },
68
+ }
69
+ expectedHistoryNoTrunc = []historyObj {
70
+ {
71
+ Snapshot : "<missing>" ,
72
+ Size : "0" ,
73
+ },
74
+ {
75
+ Snapshot : "sha256:a16e98724c05975ee8c40d8fe389c3481373d34ab20a1cf52ea2accc43f71f4c" ,
76
+ CreatedBy : "ADD alpine-minirootfs-3.21.3-aarch64.tar.gz / # buildkit" ,
77
+ Size : "8843264" ,
78
+ },
79
+ }
80
+ )
81
+
46
82
func decode (stdout string ) ([]historyObj , error ) {
47
83
dec := json .NewDecoder (strings .NewReader (stdout ))
48
84
object := []historyObj {}
@@ -95,35 +131,35 @@ func TestImageHistory(t *testing.T) {
95
131
assert .NilError (t , err , info )
96
132
assert .Equal (t , len (history ), 2 , info )
97
133
98
- localTimeL1 , _ := time .Parse (time .RFC3339 , "2021-03-31T10:21:23-07:00" )
99
- localTimeL2 , _ := time .Parse (time .RFC3339 , "2021-03-31T10:21:21-07:00" )
100
- compTime1 , _ := time .Parse (time .RFC3339 , history [0 ].CreatedAt )
101
- compTime2 , _ := time .Parse (time .RFC3339 , history [1 ].CreatedAt )
102
- assert . Equal ( t , compTime1 . UTC (). String (), localTimeL1 . UTC (). String (), info )
103
- assert .Equal (t , history [ 0 ]. CreatedBy , "/bin/sh -c #(nop) CMD [ \" /bin/sh \" ]" , info )
104
- assert .Equal (t , compTime2 . UTC (). String (), localTimeL2 . UTC (). String () , info )
105
- assert .Equal (t , history [1 ]. CreatedBy , "/bin/sh -c #(nop) ADD file:3b16ffee2b26d8af5…" , info )
106
-
107
- assert .Equal (t , history [0 ].Size , "0B" , info )
108
- assert .Equal (t , history [0 ].CreatedSince , formatter . TimeSinceInHuman ( compTime1 ) , info )
109
- assert . Equal ( t , history [ 0 ]. Snapshot , "<missing>" , info )
110
- assert .Equal (t , history [ 0 ]. Comment , "" , info )
111
-
112
- assert .Equal (t , history [1 ].Size , "5.947MB" , info )
113
- assert .Equal (t , history [1 ].CreatedSince , formatter . TimeSinceInHuman ( compTime2 ) , info )
114
- assert .Equal (t , history [1 ].Snapshot , "sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c…" , info )
115
- assert .Equal (t , history [1 ].Comment , "" , info )
134
+ h0Time , _ := time .Parse (time .RFC3339 , history [ 0 ]. CreatedAt )
135
+ h1Time , _ := time .Parse (time .RFC3339 , history [ 1 ]. CreatedAt )
136
+ comp0Time , _ := time .Parse (time .RFC3339 , expectedHistory [0 ].CreatedAt )
137
+ comp1Time , _ := time .Parse (time .RFC3339 , expectedHistory [1 ].CreatedAt )
138
+
139
+ assert .Equal (t , h0Time . UTC (). String (), comp0Time . UTC (). String () , info )
140
+ assert .Equal (t , history [ 0 ]. CreatedBy , expectedHistory [ 0 ]. CreatedBy , info )
141
+ assert .Equal (t , history [0 ]. Size , expectedHistory [ 0 ]. Size , info )
142
+ assert . Equal ( t , history [ 0 ]. CreatedSince , expectedHistory [ 0 ]. CreatedSince , info )
143
+ assert .Equal (t , history [0 ].Snapshot , expectedHistory [ 0 ]. Snapshot , info )
144
+ assert .Equal (t , history [0 ].Comment , expectedHistory [ 0 ]. Comment , info )
145
+
146
+ assert .Equal (t , h1Time . UTC (). String (), comp1Time . UTC (). String () , info )
147
+ assert . Equal ( t , history [ 1 ]. CreatedBy , expectedHistory [ 1 ]. CreatedBy , info )
148
+ assert .Equal (t , history [1 ].Size , expectedHistory [ 1 ]. Size , info )
149
+ assert .Equal (t , history [1 ].CreatedSince , expectedHistory [ 1 ]. CreatedSince , info )
150
+ assert .Equal (t , history [1 ].Snapshot , expectedHistory [ 1 ]. Snapshot , info )
151
+ assert .Equal (t , history [1 ].Comment , expectedHistory [ 1 ]. Comment , info )
116
152
}),
117
153
},
118
154
{
119
- Description : "no human - dates and sizes and not prettyfied" ,
155
+ Description : "no human - dates and sizes are not prettyfied" ,
120
156
Command : test .Command ("image" , "history" , "--human=false" , "--format=json" , testutil .CommonImage ),
121
157
Expected : test .Expects (0 , nil , func (stdout string , info string , t * testing.T ) {
122
158
history , err := decode (stdout )
123
159
assert .NilError (t , err , info )
124
- assert .Equal (t , history [0 ].Size , "0" , info )
160
+ assert .Equal (t , history [0 ].Size , expectedHistoryNoTrunc [ 0 ]. Size , info )
125
161
assert .Equal (t , history [0 ].CreatedSince , history [0 ].CreatedAt , info )
126
- assert .Equal (t , history [1 ].Size , "5947392" , info )
162
+ assert .Equal (t , history [1 ].Size , expectedHistoryNoTrunc [ 1 ]. Size , info )
127
163
assert .Equal (t , history [1 ].CreatedSince , history [1 ].CreatedAt , info )
128
164
}),
129
165
},
@@ -133,22 +169,22 @@ func TestImageHistory(t *testing.T) {
133
169
Expected : test .Expects (0 , nil , func (stdout string , info string , t * testing.T ) {
134
170
history , err := decode (stdout )
135
171
assert .NilError (t , err , info )
136
- assert .Equal (t , history [1 ].Snapshot , "sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c25bcb5155e898097cd75dc77c2a" )
137
- assert .Equal (t , history [1 ].CreatedBy , "/bin/sh -c #(nop) ADD file:3b16ffee2b26d8af5db152fcc582aaccd9e1ec9e3343874e9969a205550fe07d in / " )
172
+ assert .Equal (t , history [1 ].Snapshot , expectedHistoryNoTrunc [ 1 ]. Snapshot )
173
+ assert .Equal (t , history [1 ].CreatedBy , expectedHistoryNoTrunc [ 1 ]. CreatedBy )
138
174
}),
139
175
},
140
176
{
141
177
Description : "Quiet has no effect with format, so, go no-json, no-trunc" ,
142
178
Command : test .Command ("image" , "history" , "--human=false" , "--no-trunc" , "--quiet" , testutil .CommonImage ),
143
179
Expected : test .Expects (0 , nil , func (stdout string , info string , t * testing.T ) {
144
- assert .Equal (t , stdout , "<missing> \n sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c25bcb5155e898097cd75dc77c2a \n " )
180
+ assert .Equal (t , stdout , expectedHistoryNoTrunc [ 0 ]. Snapshot + " \n " + expectedHistoryNoTrunc [ 1 ]. Snapshot + " \n " )
145
181
}),
146
182
},
147
183
{
148
184
Description : "With quiet, trunc has no effect" ,
149
185
Command : test .Command ("image" , "history" , "--human=false" , "--no-trunc" , "--quiet" , testutil .CommonImage ),
150
186
Expected : test .Expects (0 , nil , func (stdout string , info string , t * testing.T ) {
151
- assert .Equal (t , stdout , "<missing> \n sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c25bcb5155e898097cd75dc77c2a \n " )
187
+ assert .Equal (t , stdout , expectedHistoryNoTrunc [ 0 ]. Snapshot + " \n " + expectedHistoryNoTrunc [ 1 ]. Snapshot + " \n " )
152
188
}),
153
189
},
154
190
},
0 commit comments