...
1
16
17 package container
18
19 import (
20 "errors"
21 "testing"
22 )
23
24 func TestPodSyncResult(t *testing.T) {
25 okResults := []*SyncResult{
26 NewSyncResult(StartContainer, "container_0"),
27 NewSyncResult(SetupNetwork, "pod"),
28 }
29 errResults := []*SyncResult{
30 NewSyncResult(KillContainer, "container_1"),
31 NewSyncResult(TeardownNetwork, "pod"),
32 }
33 errResults[0].Fail(errors.New("error_0"), "message_0")
34 errResults[1].Fail(errors.New("error_1"), "message_1")
35
36
37 result := PodSyncResult{}
38 result.AddSyncResult(okResults...)
39 if result.Error() != nil {
40 t.Errorf("PodSyncResult should not be error: %v", result)
41 }
42
43
44 result = PodSyncResult{}
45 result.AddSyncResult(okResults...)
46 result.AddSyncResult(errResults...)
47 if result.Error() == nil {
48 t.Errorf("PodSyncResult should be error: %v", result)
49 }
50
51
52 result = PodSyncResult{}
53 result.AddSyncResult(okResults...)
54 result.Fail(errors.New("error"))
55 if result.Error() == nil {
56 t.Errorf("PodSyncResult should be error: %v", result)
57 }
58
59
60 errResult := PodSyncResult{}
61 errResult.AddSyncResult(errResults...)
62 result = PodSyncResult{}
63 result.AddSyncResult(okResults...)
64 result.AddPodSyncResult(errResult)
65 if result.Error() == nil {
66 t.Errorf("PodSyncResult should be error: %v", result)
67 }
68 }
69
View as plain text