@@ -44,6 +44,43 @@ type historyObj struct {
4444 Comment string
4545}
4646
47+ const createdAt1 = "2021-03-31T10:21:21-07:00"
48+ const createdAt2 = "2021-03-31T10:21:23-07:00"
49+
50+ // Expected content of the common image on arm64
51+ var (
52+ createdAtTime , _ = time .Parse (time .RFC3339 , createdAt2 )
53+ expectedHistory = []historyObj {
54+ {
55+ CreatedBy : "/bin/sh -c #(nop) CMD [\" /bin/sh\" ]" ,
56+ Size : "0B" ,
57+ CreatedAt : createdAt2 ,
58+ Snapshot : "<missing>" ,
59+ Comment : "" ,
60+ CreatedSince : formatter .TimeSinceInHuman (createdAtTime ),
61+ },
62+ {
63+ CreatedBy : "/bin/sh -c #(nop) ADD file:3b16ffee2b26d8af5…" ,
64+ Size : "5.947MB" ,
65+ CreatedAt : createdAt1 ,
66+ Snapshot : "sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c…" ,
67+ Comment : "" ,
68+ CreatedSince : formatter .TimeSinceInHuman (createdAtTime ),
69+ },
70+ }
71+ expectedHistoryNoTrunc = []historyObj {
72+ {
73+ Snapshot : "<missing>" ,
74+ Size : "0" ,
75+ },
76+ {
77+ Snapshot : "sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c25bcb5155e898097cd75dc77c2a" ,
78+ CreatedBy : "/bin/sh -c #(nop) ADD file:3b16ffee2b26d8af5db152fcc582aaccd9e1ec9e3343874e9969a205550fe07d in / " ,
79+ Size : "5947392" ,
80+ },
81+ }
82+ )
83+
4784func decode (stdout string ) ([]historyObj , error ) {
4885 dec := json .NewDecoder (strings .NewReader (stdout ))
4986 object := []historyObj {}
@@ -96,35 +133,35 @@ func TestImageHistory(t *testing.T) {
96133 assert .NilError (t , err , "decode should not fail" )
97134 assert .Equal (t , len (history ), 2 , "history should be 2 in length" )
98135
99- localTimeL1 , _ := time .Parse (time .RFC3339 , "2021-03-31T10:21:23-07:00" )
100- localTimeL2 , _ := time .Parse (time .RFC3339 , "2021-03-31T10:21:21-07:00" )
101- compTime1 , _ := time .Parse (time .RFC3339 , history [0 ].CreatedAt )
102- compTime2 , _ := time .Parse (time .RFC3339 , history [1 ].CreatedAt )
103- assert . Equal ( t , compTime1 . UTC (). String (), localTimeL1 . UTC (). String ())
104- assert .Equal (t , history [ 0 ]. CreatedBy , "/bin/sh -c #(nop) CMD [ \" /bin/sh \" ]" )
105- assert .Equal (t , compTime2 . UTC (). String (), localTimeL2 . UTC (). String () )
106- assert .Equal (t , history [1 ]. CreatedBy , "/bin/sh -c #(nop) ADD file:3b16ffee2b26d8af5…" )
107-
108- assert .Equal (t , history [0 ].Size , "0B" )
109- assert .Equal (t , history [0 ].CreatedSince , formatter . TimeSinceInHuman ( compTime1 ) )
110- assert . Equal ( t , history [ 0 ]. Snapshot , "<missing>" )
111- assert .Equal (t , history [ 0 ]. Comment , "" )
112-
113- assert .Equal (t , history [1 ].Size , "5.947MB" )
114- assert .Equal (t , history [1 ].CreatedSince , formatter . TimeSinceInHuman ( compTime2 ) )
115- assert .Equal (t , history [1 ].Snapshot , "sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c…" )
116- assert .Equal (t , history [1 ].Comment , "" )
136+ h0Time , _ := time .Parse (time .RFC3339 , history [ 0 ]. CreatedAt )
137+ h1Time , _ := time .Parse (time .RFC3339 , history [ 1 ]. CreatedAt )
138+ comp0Time , _ := time .Parse (time .RFC3339 , expectedHistory [0 ].CreatedAt )
139+ comp1Time , _ := time .Parse (time .RFC3339 , expectedHistory [1 ].CreatedAt )
140+
141+ assert .Equal (t , h0Time . UTC (). String (), comp0Time . UTC (). String () )
142+ assert .Equal (t , history [ 0 ]. CreatedBy , expectedHistory [ 0 ]. CreatedBy )
143+ assert .Equal (t , history [0 ]. Size , expectedHistory [ 0 ]. Size )
144+ assert . Equal ( t , history [ 0 ]. CreatedSince , expectedHistory [ 0 ]. CreatedSince )
145+ assert .Equal (t , history [0 ].Snapshot , expectedHistory [ 0 ]. Snapshot )
146+ assert .Equal (t , history [0 ].Comment , expectedHistory [ 0 ]. Comment )
147+
148+ assert .Equal (t , h1Time . UTC (). String (), comp1Time . UTC (). String () )
149+ assert . Equal ( t , history [ 1 ]. CreatedBy , expectedHistory [ 1 ]. CreatedBy )
150+ assert .Equal (t , history [1 ].Size , expectedHistory [ 1 ]. Size )
151+ assert .Equal (t , history [1 ].CreatedSince , expectedHistory [ 1 ]. CreatedSince )
152+ assert .Equal (t , history [1 ].Snapshot , expectedHistory [ 1 ]. Snapshot )
153+ assert .Equal (t , history [1 ].Comment , expectedHistory [ 1 ]. Comment )
117154 }),
118155 },
119156 {
120- Description : "no human - dates and sizes and not prettyfied" ,
157+ Description : "no human - dates and sizes are not prettyfied" ,
121158 Command : test .Command ("image" , "history" , "--human=false" , "--format=json" , testutil .CommonImage ),
122159 Expected : test .Expects (0 , nil , func (stdout string , t tig.T ) {
123160 history , err := decode (stdout )
124161 assert .NilError (t , err , "decode should not fail" )
125- assert .Equal (t , history [0 ].Size , "0" )
162+ assert .Equal (t , history [0 ].Size , expectedHistoryNoTrunc [ 0 ]. Size )
126163 assert .Equal (t , history [0 ].CreatedSince , history [0 ].CreatedAt )
127- assert .Equal (t , history [1 ].Size , "5947392" )
164+ assert .Equal (t , history [1 ].Size , expectedHistoryNoTrunc [ 1 ]. Size )
128165 assert .Equal (t , history [1 ].CreatedSince , history [1 ].CreatedAt )
129166 }),
130167 },
@@ -134,22 +171,22 @@ func TestImageHistory(t *testing.T) {
134171 Expected : test .Expects (0 , nil , func (stdout string , t tig.T ) {
135172 history , err := decode (stdout )
136173 assert .NilError (t , err , "decode should not fail" )
137- assert .Equal (t , history [1 ].Snapshot , "sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c25bcb5155e898097cd75dc77c2a" )
138- assert .Equal (t , history [1 ].CreatedBy , "/bin/sh -c #(nop) ADD file:3b16ffee2b26d8af5db152fcc582aaccd9e1ec9e3343874e9969a205550fe07d in / " )
174+ assert .Equal (t , history [1 ].Snapshot , expectedHistoryNoTrunc [ 1 ]. Snapshot )
175+ assert .Equal (t , history [1 ].CreatedBy , expectedHistoryNoTrunc [ 1 ]. CreatedBy )
139176 }),
140177 },
141178 {
142179 Description : "Quiet has no effect with format, so, go no-json, no-trunc" ,
143180 Command : test .Command ("image" , "history" , "--human=false" , "--no-trunc" , "--quiet" , testutil .CommonImage ),
144181 Expected : test .Expects (0 , nil , func (stdout string , t tig.T ) {
145- assert .Equal (t , stdout , "<missing> \n sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c25bcb5155e898097cd75dc77c2a \n " )
182+ assert .Equal (t , stdout , expectedHistoryNoTrunc [ 0 ]. Snapshot + " \n " + expectedHistoryNoTrunc [ 1 ]. Snapshot + " \n " )
146183 }),
147184 },
148185 {
149186 Description : "With quiet, trunc has no effect" ,
150187 Command : test .Command ("image" , "history" , "--human=false" , "--no-trunc" , "--quiet" , testutil .CommonImage ),
151188 Expected : test .Expects (0 , nil , func (stdout string , t tig.T ) {
152- assert .Equal (t , stdout , "<missing> \n sha256:56bf55b8eed1f0b4794a30386e4d1d3da949c25bcb5155e898097cd75dc77c2a \n " )
189+ assert .Equal (t , stdout , expectedHistoryNoTrunc [ 0 ]. Snapshot + " \n " + expectedHistoryNoTrunc [ 1 ]. Snapshot + " \n " )
153190 }),
154191 },
155192 },
0 commit comments