-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_load_unit_test
42 lines (36 loc) · 1.3 KB
/
add_load_unit_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
func TestLoadImage(t *testing.T) {
// create cluster
c := &Cluster{
engines: make(map[string]*cluster.Engine),
}
// create engione
id := "test-engine"
engine := cluster.NewEngine(id, 0)
engine.Name = id
engine.ID = id
// create mock client
client := mockclient.NewMockClient()
client.On("Info").Return(mockInfo, nil)
client.On("StartMonitorEvents", mock.Anything, mock.Anything, mock.Anything).Return()
client.On("ListContainers", true, false, "").Return([]dockerclient.Container{}, nil).Once()
client.On("ListImages").Return([]*dockerclient.Image{}, nil)
// connect client
engine.ConnectWithClient(client)
// add engine to cluster
c.engines[engine.ID] = engine
// load success
client.On("LoadImage", mock.AnythingOfType("*io.PipeReader")).Return(nil).Once()
callback := func(what, status string) {
//if load OK, will not come here
t.Fatalf("Load error")
}
c.Load(bytes.NewReader(nil), callback)
// load error
err := fmt.Errorf("Import error")
client.On("LoadImage", mock.AnythingOfType("*io.PipeReader")).Return(err).Once()
callback = func(what, status string) {
// load error
assert.Equal(t, status, "Import error")
}
c.Load(bytes.NewReader(nil), callback)
}