@@ -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" ,
@@ -69,6 +68,18 @@ func TestContainerStore(t *testing.T) {
6968 ImageRef : "TestImage-3" ,
7069 LogPath : "/test/log/path/3" ,
7170 },
71+ "4abcd" : {
72+ ID : "4abcd" ,
73+ Name : "Container-4abcd" ,
74+ SandboxID : "Sandbox-4abcd" ,
75+ Config : & runtime.ContainerConfig {
76+ Metadata : & runtime.ContainerMetadata {
77+ Name : "TestPod-4abcd" ,
78+ Attempt : 1 ,
79+ },
80+ },
81+ ImageRef : "TestImage-4abcd" ,
82+ },
7283 }
7384 statuses := map [string ]Status {
7485 "1" : {
@@ -99,12 +110,22 @@ func TestContainerStore(t *testing.T) {
99110 Message : "TestMessage-3" ,
100111 Removing : true ,
101112 },
113+ "4abcd" : {
114+ Pid : 4 ,
115+ CreatedAt : time .Now ().UnixNano (),
116+ StartedAt : time .Now ().UnixNano (),
117+ FinishedAt : time .Now ().UnixNano (),
118+ ExitCode : 4 ,
119+ Reason : "TestReason-4abcd" ,
120+ Message : "TestMessage-4abcd" ,
121+ Removing : true ,
122+ },
102123 }
103124 assert := assertlib .New (t )
104125 containers := map [string ]Container {}
105- for _ , id := range ids {
126+ for id , v := range metadatas {
106127 container , err := NewContainer (
107- metadatas [ id ] ,
128+ v ,
108129 WithFakeStatus (statuses [id ]),
109130 )
110131 assert .NoError (err )
@@ -119,29 +140,35 @@ func TestContainerStore(t *testing.T) {
119140 }
120141
121142 t .Logf ("should be able to get container" )
143+ genTruncIndex := func (normalName string ) string { return normalName [:(len (normalName )+ 1 )/ 2 ] }
122144 for id , c := range containers {
123- got , err := s .Get (id )
145+ got , err := s .Get (genTruncIndex ( id ) )
124146 assert .NoError (err )
125147 assert .Equal (c , got )
126148 }
127149
128150 t .Logf ("should be able to list containers" )
129151 cs := s .List ()
130- assert .Len (cs , 3 )
152+ assert .Len (cs , len (containers ))
153+
154+ cntrNum := len (containers )
155+ for testID , v := range containers {
156+ truncID := genTruncIndex (testID )
131157
132- testID := "2"
133- t .Logf ("add should return already exists error for duplicated container" )
134- assert .Equal (store .ErrAlreadyExist , s .Add (containers [testID ]))
158+ t .Logf ("add should return already exists error for duplicated container" )
159+ assert .Equal (store .ErrAlreadyExist , s .Add (v ))
135160
136- t .Logf ("should be able to delete container" )
137- s .Delete (testID )
138- cs = s .List ()
139- assert .Len (cs , 2 )
161+ t .Logf ("should be able to delete container" )
162+ s .Delete (truncID )
163+ cntrNum --
164+ cs = s .List ()
165+ assert .Len (cs , cntrNum )
140166
141- t .Logf ("get should return not exist error after deletion" )
142- c , err := s .Get (testID )
143- assert .Equal (Container {}, c )
144- assert .Equal (store .ErrNotExist , err )
167+ t .Logf ("get should return not exist error after deletion" )
168+ c , err := s .Get (truncID )
169+ assert .Equal (Container {}, c )
170+ assert .Equal (store .ErrNotExist , err )
171+ }
145172}
146173
147174func TestWithContainerIO (t * testing.T ) {
0 commit comments