@@ -33,7 +33,7 @@ func TestNewHookTracker(t *testing.T) {
3333func TestHookTracker_Add (t * testing.T ) {
3434 tracker := NewHookTracker ()
3535
36- tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
36+ tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
3737
3838 key := hookKey {
3939 podNamespace : "ns1" ,
@@ -50,8 +50,8 @@ func TestHookTracker_Add(t *testing.T) {
5050
5151func TestHookTracker_Record (t * testing.T ) {
5252 tracker := NewHookTracker ()
53- tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
54- err := tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
53+ tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
54+ err := tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
5555
5656 key := hookKey {
5757 podNamespace : "ns1" ,
@@ -67,40 +67,41 @@ func TestHookTracker_Record(t *testing.T) {
6767 assert .True (t , info .hookExecuted )
6868 assert .NoError (t , err )
6969
70- err = tracker .Record ("ns2" , "pod2" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
70+ err = tracker .Record ("ns2" , "pod2" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
7171 assert .Error (t , err )
7272
73- err = tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , false , nil )
73+ err = tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , false , nil )
7474 assert .NoError (t , err )
7575 assert .True (t , info .hookFailed )
7676}
7777
7878func TestHookTracker_Stat (t * testing.T ) {
7979 tracker := NewHookTracker ()
8080
81- tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
82- tracker .Add ("ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" )
83- tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
81+ tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
82+ tracker .Add ("ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" , 0 )
83+ tracker .Add ("ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" , 1 )
84+ tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
8485
8586 attempted , failed := tracker .Stat ()
86- assert .Equal (t , 2 , attempted )
87+ assert .Equal (t , 3 , attempted )
8788 assert .Equal (t , 1 , failed )
8889}
8990
9091func TestHookTracker_IsComplete (t * testing.T ) {
9192 tracker := NewHookTracker ()
92- tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , PhasePre )
93- tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , PhasePre , true , fmt .Errorf ("err" ))
93+ tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , PhasePre , 0 )
94+ tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , PhasePre , 0 , true , fmt .Errorf ("err" ))
9495 assert .True (t , tracker .IsComplete ())
9596
96- tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
97+ tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
9798 assert .False (t , tracker .IsComplete ())
9899}
99100
100101func TestHookTracker_HookErrs (t * testing.T ) {
101102 tracker := NewHookTracker ()
102- tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
103- tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
103+ tracker .Add ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
104+ tracker .Record ("ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
104105
105106 hookErrs := tracker .HookErrs ()
106107 assert .Len (t , hookErrs , 1 )
@@ -109,7 +110,7 @@ func TestHookTracker_HookErrs(t *testing.T) {
109110func TestMultiHookTracker_Add (t * testing.T ) {
110111 mht := NewMultiHookTracker ()
111112
112- mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
113+ mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
113114
114115 key := hookKey {
115116 podNamespace : "ns1" ,
@@ -118,6 +119,7 @@ func TestMultiHookTracker_Add(t *testing.T) {
118119 hookPhase : "" ,
119120 hookSource : HookSourceAnnotation ,
120121 hookName : "h1" ,
122+ hookIndex : 0 ,
121123 }
122124
123125 _ , ok := mht .trackers ["restore1" ].tracker [key ]
@@ -126,8 +128,8 @@ func TestMultiHookTracker_Add(t *testing.T) {
126128
127129func TestMultiHookTracker_Record (t * testing.T ) {
128130 mht := NewMultiHookTracker ()
129- mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
130- err := mht .Record ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
131+ mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
132+ err := mht .Record ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
131133
132134 key := hookKey {
133135 podNamespace : "ns1" ,
@@ -136,36 +138,39 @@ func TestMultiHookTracker_Record(t *testing.T) {
136138 hookPhase : "" ,
137139 hookSource : HookSourceAnnotation ,
138140 hookName : "h1" ,
141+ hookIndex : 0 ,
139142 }
140143
141144 info := mht .trackers ["restore1" ].tracker [key ]
142145 assert .True (t , info .hookFailed )
143146 assert .True (t , info .hookExecuted )
144147 assert .NoError (t , err )
145148
146- err = mht .Record ("restore1" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
149+ err = mht .Record ("restore1" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
147150 assert .Error (t , err )
148151
149- err = mht .Record ("restore2" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
152+ err = mht .Record ("restore2" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
150153 assert .Error (t , err )
151154}
152155
153156func TestMultiHookTracker_Stat (t * testing.T ) {
154157 mht := NewMultiHookTracker ()
155158
156- mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
157- mht .Add ("restore1" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" )
158- mht .Record ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
159- mht .Record ("restore1" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" , false , nil )
159+ mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
160+ mht .Add ("restore1" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" , 0 )
161+ mht .Add ("restore1" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" , 1 )
162+ mht .Record ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
163+ mht .Record ("restore1" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" , 0 , false , nil )
164+ mht .Record ("restore1" , "ns2" , "pod2" , "container1" , HookSourceAnnotation , "h2" , "" , 1 , false , nil )
160165
161166 attempted , failed := mht .Stat ("restore1" )
162- assert .Equal (t , 2 , attempted )
167+ assert .Equal (t , 3 , attempted )
163168 assert .Equal (t , 1 , failed )
164169}
165170
166171func TestMultiHookTracker_Delete (t * testing.T ) {
167172 mht := NewMultiHookTracker ()
168- mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
173+ mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
169174 mht .Delete ("restore1" )
170175
171176 _ , ok := mht .trackers ["restore1" ]
@@ -174,20 +179,20 @@ func TestMultiHookTracker_Delete(t *testing.T) {
174179
175180func TestMultiHookTracker_IsComplete (t * testing.T ) {
176181 mht := NewMultiHookTracker ()
177- mht .Add ("backup1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , PhasePre )
178- mht .Record ("backup1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , PhasePre , true , fmt .Errorf ("err" ))
182+ mht .Add ("backup1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , PhasePre , 0 )
183+ mht .Record ("backup1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , PhasePre , 0 , true , fmt .Errorf ("err" ))
179184 assert .True (t , mht .IsComplete ("backup1" ))
180185
181- mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
186+ mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
182187 assert .False (t , mht .IsComplete ("restore1" ))
183188
184189 assert .True (t , mht .IsComplete ("restore2" ))
185190}
186191
187192func TestMultiHookTracker_HookErrs (t * testing.T ) {
188193 mht := NewMultiHookTracker ()
189- mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" )
190- mht .Record ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , true , fmt .Errorf ("err" ))
194+ mht .Add ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 )
195+ mht .Record ("restore1" , "ns1" , "pod1" , "container1" , HookSourceAnnotation , "h1" , "" , 0 , true , fmt .Errorf ("err" ))
191196
192197 hookErrs := mht .HookErrs ("restore1" )
193198 assert .Len (t , hookErrs , 1 )
0 commit comments