@@ -28,7 +28,6 @@ import (
2828)
2929
3030func TestContainerStore (t * testing.T ) {
31- ids := []string {"1" , "2" , "3" }
3231 metadatas := map [string ]Metadata {
3332 "1" : {
3433 ID : "1" ,
@@ -66,6 +65,18 @@ func TestContainerStore(t *testing.T) {
6665 },
6766 ImageRef : "TestImage-3" ,
6867 },
68+ "4abcd" : {
69+ ID : "4abcd" ,
70+ Name : "Container-4abcd" ,
71+ SandboxID : "Sandbox-4abcd" ,
72+ Config : & runtime.ContainerConfig {
73+ Metadata : & runtime.ContainerMetadata {
74+ Name : "TestPod-4abcd" ,
75+ Attempt : 1 ,
76+ },
77+ },
78+ ImageRef : "TestImage-4abcd" ,
79+ },
6980 }
7081 statuses := map [string ]Status {
7182 "1" : {
@@ -96,12 +107,22 @@ func TestContainerStore(t *testing.T) {
96107 Message : "TestMessage-3" ,
97108 Removing : true ,
98109 },
110+ "4abcd" : {
111+ Pid : 4 ,
112+ CreatedAt : time .Now ().UnixNano (),
113+ StartedAt : time .Now ().UnixNano (),
114+ FinishedAt : time .Now ().UnixNano (),
115+ ExitCode : 4 ,
116+ Reason : "TestReason-4abcd" ,
117+ Message : "TestMessage-4abcd" ,
118+ Removing : true ,
119+ },
99120 }
100121 assert := assertlib .New (t )
101122 containers := map [string ]Container {}
102- for _ , id := range ids {
123+ for id , v := range metadatas {
103124 container , err := NewContainer (
104- metadatas [ id ] ,
125+ v ,
105126 WithFakeStatus (statuses [id ]),
106127 )
107128 assert .NoError (err )
@@ -116,29 +137,35 @@ func TestContainerStore(t *testing.T) {
116137 }
117138
118139 t .Logf ("should be able to get container" )
140+ genTruncIndex := func (normalName string ) string { return normalName [:(len (normalName )+ 1 )/ 2 ] }
119141 for id , c := range containers {
120- got , err := s .Get (id )
142+ got , err := s .Get (genTruncIndex ( id ) )
121143 assert .NoError (err )
122144 assert .Equal (c , got )
123145 }
124146
125147 t .Logf ("should be able to list containers" )
126148 cs := s .List ()
127- assert .Len (cs , 3 )
149+ assert .Len (cs , len (containers ))
150+
151+ cntrNum := len (containers )
152+ for testID , v := range containers {
153+ truncID := genTruncIndex (testID )
128154
129- testID := "2"
130- t .Logf ("add should return already exists error for duplicated container" )
131- assert .Equal (store .ErrAlreadyExist , s .Add (containers [testID ]))
155+ t .Logf ("add should return already exists error for duplicated container" )
156+ assert .Equal (store .ErrAlreadyExist , s .Add (v ))
132157
133- t .Logf ("should be able to delete container" )
134- s .Delete (testID )
135- cs = s .List ()
136- assert .Len (cs , 2 )
158+ t .Logf ("should be able to delete container" )
159+ s .Delete (truncID )
160+ cntrNum --
161+ cs = s .List ()
162+ assert .Len (cs , cntrNum )
137163
138- t .Logf ("get should return not exist error after deletion" )
139- c , err := s .Get (testID )
140- assert .Equal (Container {}, c )
141- assert .Equal (store .ErrNotExist , err )
164+ t .Logf ("get should return not exist error after deletion" )
165+ c , err := s .Get (truncID )
166+ assert .Equal (Container {}, c )
167+ assert .Equal (store .ErrNotExist , err )
168+ }
142169}
143170
144171func TestWithContainerIO (t * testing.T ) {
0 commit comments