Exemple #1
0
func TestPrintIt(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockfmt.MOCK().SetController(ctrl)

	mockfmt.EXPECT().Println("Got a", 10)

	PrintIt(10)
}
func (s *MaestroTestSuite) TestCheckRunningContainerShouldUseDockerPs(c *C) {
	// Create a gomock controller, and arrange for it's finish to be called
	ctrl := gomock.NewController(c)
	defer ctrl.Finish()

	// Setup the docker mock package
	docker.MOCK().SetController(ctrl)

	// Setup the mockfmt mock package
	mockfmt.MOCK().SetController(ctrl)

	psResult := make(map[string]string)
	psResult["gaudi/lb"] = "123"
	psResult["gaudi/front1"] = "124"
	psResult["gaudi/db"] = "125"

	docker.EXPECT().SnapshotProcesses().Return(psResult, nil)
	docker.EXPECT().Inspect("123").Return([]byte("[{\"ID\": \"123\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"123.124.125.126\"}}]"), nil)
	docker.EXPECT().Inspect("124").Return([]byte("[{\"ID\": \"123\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"123.124.125.127\"}}]"), nil)
	docker.EXPECT().Inspect("125").Return([]byte("[{\"ID\": \"123\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"123.124.125.128\"}}]"), nil)

	mockfmt.EXPECT().Println("Application", "lb", "is running", "(123.124.125.126:)")
	mockfmt.EXPECT().Println("Application", "front1", "is running", "(123.124.125.127:)")
	mockfmt.EXPECT().Println("Application", "db", "is running", "(123.124.125.128:3306)")

	m := maestro.Maestro{}
	m.InitFromString(`
applications:
    lb:
        links: [front1]
        type: varnish

    front1:
        type: apache

    db:
        type: mysql
        ports:
            3306: 9000
`, "")

	m.Check()
}
Exemple #3
0
func TestShow(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	fmt.MOCK().SetController(ctrl)

	// We need some test data
	data := "one\ntwo\nthree"

	// The test data contains three lines that we expect to be printed.
	fmt.EXPECT().Printf("%d: %s\n", 1, "one")
	fmt.EXPECT().Printf("%d: %s\n", 2, "two")
	fmt.EXPECT().Printf("%d: %s\n", 3, "three")

	// Run the function we want to test
	err := Show(data)

	if err != nil {
		t.Errorf("Unexpected error return: %s", err)
	}
}
Exemple #4
0
func TestShow(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	fmt.MOCK().SetController(ctrl)

	// We need to find out test data file
	path := filepath.Join(testDataPath(), "count")

	// The count file contains three lines that we expect to be printed.
	fmt.EXPECT().Printf("%d: %s\n", 1, "one")
	fmt.EXPECT().Printf("%d: %s\n", 2, "two")
	fmt.EXPECT().Printf("%d: %s\n", 3, "three")

	// Run the function we want to test
	err := Show(path)

	if err != nil {
		t.Errorf("Unexpected error return: %s", err)
	}
}