func TestStartService(t *testing.T) { tests := []struct { name string file string expectRestart bool }{ { name: "ChildDir", file: "shipshape/cli/testdata/workspace2/subworkspace1", expectRestart: true, }, { name: "SiblingDir", file: "shipshape/cli/testdata/workspace2/subworkspace2", expectRestart: true, }, { name: "ParentDir", file: "shipshape/cli/testdata/workspace2", expectRestart: true, }, { name: "SameDir", file: "shipshape/cli/testdata/workspace2", expectRestart: false, }, { name: "File", file: "shipshape/cli/testdata/workspace2/test.js", expectRestart: false, }, { name: "ParentToChild", file: "shipshape/cli/testdata/workspace2/subworkspace2", expectRestart: false, }, { name: "ParentToOtherChild", file: "shipshape/cli/testdata/workspace2/subworkspace1", expectRestart: false, }, } container := "shipping_container" cleanExistingContainer(t, container) oldId := "" for _, test := range tests { options := Options{ File: test.file, ThirdPartyAnalyzers: []string{}, Build: "", TriggerCats: []string{}, Dind: false, Event: defaults.DefaultEvent, Repo: defaults.DefaultRepo, StayUp: true, Tag: *dockerTag, LocalKythe: *localKythe, } if err := New(options).StartService(); err != nil { t.Fatalf("%v: Failure on service call; err: %v", test.name, err) } newId, err := docker.ContainerId(container) if err != nil { t.Fatalf("%v: Could not get container id: %v", test.name, err) } if got, want := newId != oldId, test.expectRestart; got != want { t.Errorf("%v: Incorrect restart status for container. Got %v, want %v", test.name, got, want) } oldId = newId } }
func TestChangingDirs(t *testing.T) { tests := []struct { name string file string expectedJSHint int expectedGovet int expectedPyLint int expectRestart bool }{ { name: "ChildDir", file: "shipshape/cli/testdata/workspace2/subworkspace1", expectedJSHint: 0, expectedGovet: 1, expectedPyLint: 0, expectRestart: true, }, { name: "SiblingDir", file: "shipshape/cli/testdata/workspace2/subworkspace2", expectedJSHint: 0, expectedGovet: 0, expectedPyLint: 22, expectRestart: true, }, { name: "ParentDir", file: "shipshape/cli/testdata/workspace2", expectedJSHint: 3, expectedGovet: 1, expectedPyLint: 22, expectRestart: true, }, { name: "File", file: "shipshape/cli/testdata/workspace2/test.js", expectedJSHint: 3, expectedGovet: 0, expectedPyLint: 0, expectRestart: false, }, { name: "ParentToChild", file: "shipshape/cli/testdata/workspace2/subworkspace2", expectedJSHint: 0, expectedGovet: 0, expectedPyLint: 22, expectRestart: false, }, { name: "ParentToOtherChild", file: "shipshape/cli/testdata/workspace2/subworkspace1", expectedJSHint: 0, expectedGovet: 1, expectedPyLint: 0, expectRestart: false, }, } // Clean up the docker state container := "shipping_container" cleanExistingContainer(t, container) oldId := "" for _, test := range tests { options := Options{ File: test.file, ThirdPartyAnalyzers: []string{}, Build: "", TriggerCats: []string{"JSHint", "go vet", "PyLint"}, Dind: false, Event: defaults.DefaultEvent, Repo: defaults.DefaultRepo, StayUp: true, Tag: *dockerTag, LocalKythe: *localKythe, } var allResponses rpcpb.ShipshapeResponse options.HandleResponse = func(shipshapeResp *rpcpb.ShipshapeResponse, _ string) error { allResponses.AnalyzeResponse = append(allResponses.AnalyzeResponse, shipshapeResp.AnalyzeResponse...) return nil } testName := test.name if _, err := New(options).Run(); err != nil { t.Fatalf("%v: Failure on service call; err: %v", testName, err) } if got, want := countFailures(allResponses), 0; got != want { t.Errorf("%v: Wrong number of failures; got %v, want %v (proto data: %v)", testName, got, want, allResponses) } if got, want := countCategoryNotes(allResponses, "JSHint"), test.expectedJSHint; got != want { t.Errorf("%v: Wrong number of JSHint notes; got %v, want %v (proto data: %v)", testName, got, want, allResponses) } if got, want := countCategoryNotes(allResponses, "go vet"), test.expectedGovet; got != want { t.Errorf("%v: Wrong number of go vet notes; got %v, want %v (proto data: %v)", testName, got, want, allResponses) } if got, want := countCategoryNotes(allResponses, "PyLint"), test.expectedPyLint; got != want { t.Errorf("%v: Wrong number of PyLint notes; got %v, want %v (proto data: %v)", testName, got, want, allResponses) } newId, err := docker.ContainerId(container) if err != nil { t.Fatalf("%v: Could not get container id: %v", testName, err) } if got, want := newId != oldId, test.expectRestart; got != want { t.Errorf("%v: Incorrect restart status for container. Got %v, want %v", testName, got, want) } oldId = newId } }