コード例 #1
0
ファイル: diff_test.go プロジェクト: grammarly/rocker-compose
func TestDiffInDependentNet(t *testing.T) {
	cmp := NewDiff("test")
	c2NetName, err := config.NewNetFromString("container:test.2")
	if err != nil {
		t.Fatal(err)
	}
	c1 := &Container{
		State:  &ContainerState{Running: true},
		Name:   &config.ContainerName{Namespace: "test", Name: "1"},
		Config: &config.Container{Net: c2NetName},
	}
	c2 := &Container{
		State:  &ContainerState{Running: true},
		Name:   &config.ContainerName{Namespace: "test", Name: "2"},
		Config: &config.Container{},
	}
	c2x := &Container{
		State:  &ContainerState{Running: true},
		Name:   &config.ContainerName{Namespace: "test", Name: "2"},
		Config: &config.Container{Labels: map[string]string{"test": "test2"}},
	}
	actions, _ := cmp.Diff([]*Container{c1, c2x}, []*Container{c1, c2})
	mock := clientMock{}
	mock.On("RemoveContainer", c2).Return(nil)
	mock.On("RunContainer", c2x).Return(nil)
	mock.On("RemoveContainer", c1).Return(nil)
	mock.On("RunContainer", c1).Return(nil)
	runner := NewDockerClientRunner(&mock)
	runner.Run(actions)
	mock.AssertExpectations(t)
}
コード例 #2
0
ファイル: diff_test.go プロジェクト: grammarly/rocker-compose
func TestDiffInDependentExternalNet(t *testing.T) {
	cmp := NewDiff("test")
	c2NetName, err := config.NewNetFromString("container:external.2")
	if err != nil {
		t.Fatal(err)
	}
	c1 := &Container{
		State:  &ContainerState{Running: true},
		Name:   &config.ContainerName{Namespace: "test", Name: "1"},
		Config: &config.Container{Net: c2NetName},
	}
	c2 := newContainer("external", "2")
	actions, _ := cmp.Diff([]*Container{c1}, []*Container{c1, c2})
	mock := clientMock{}
	mock.On("EnsureContainerExist", c2).Return(nil)
	runner := NewDockerClientRunner(&mock)
	runner.Run(actions)
	mock.AssertExpectations(t)
}