Fixed gocyclo warnings and added pre-commit hook

This commit is contained in:
Oleg Atamanenko
2018-06-09 23:18:40 -04:00
parent 2b05d39067
commit 5c8d82aed0
4 changed files with 103 additions and 88 deletions

View File

@@ -12,6 +12,7 @@ before_install:
- go get -u golang.org/x/tools/cmd/goimports - go get -u golang.org/x/tools/cmd/goimports
- go get -u github.com/onsi/ginkgo/ginkgo - go get -u github.com/onsi/ginkgo/ginkgo
- go get -u github.com/monopole/mdrip - go get -u github.com/monopole/mdrip
- go get -u github.com/fzipp/gocyclo
# Install must be set to prevent default `go get` to run. # Install must be set to prevent default `go get` to run.
# The dependencies have already been vendored by `dep` so # The dependencies have already been vendored by `dep` so

View File

@@ -31,6 +31,11 @@ function testGoFmt {
diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l) diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l)
} }
function testGoCyclo {
diff <(echo -n) <(go_dirs | xargs -0 gocyclo -over 15)
}
function testGoImports { function testGoImports {
diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l) diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l)
} }
@@ -50,6 +55,7 @@ function testExamples {
runTest testGoFmt runTest testGoFmt
runTest testGoImports runTest testGoImports
runTest testGoVet runTest testGoVet
runTest testGoCyclo
runTest testGoTest runTest testGoTest
runTest testExamples runTest testExamples

View File

@@ -104,7 +104,12 @@ func TestBuild(t *testing.T) {
} }
for _, testcaseName := range testcases.List() { for _, testcaseName := range testcases.List() {
t.Run(testcaseName, func(t *testing.T) { t.Run(testcaseName, func(t *testing.T) { runBuildTestCase(t, testcaseName, updateKustomizeExpected, fs) })
}
}
func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected bool, fs fs.FileSystem) {
name := testcaseName name := testcaseName
testcase := buildTestCase{} testcase := buildTestCase{}
testcaseDir := filepath.Join("testdata", "testcase-"+name) testcaseDir := filepath.Join("testdata", "testcase-"+name)
@@ -146,7 +151,4 @@ func TestBuild(t *testing.T) {
ioutil.WriteFile(testcase.ExpectedStdout, actualBytes, 0644) ioutil.WriteFile(testcase.ExpectedStdout, actualBytes, 0644)
} }
})
}
} }

View File

@@ -74,6 +74,14 @@ func TestDiff(t *testing.T) {
for _, testcaseName := range testcases.List() { for _, testcaseName := range testcases.List() {
t.Run(testcaseName, func(t *testing.T) { t.Run(testcaseName, func(t *testing.T) {
runDiffTestCase(t, testcaseName, updateKustomizeExpected, fs,
noopDir, transformedDir, timestamp)
})
}
}
func runDiffTestCase(t *testing.T, testcaseName string, updateKustomizeExpected bool, fs fs.FileSystem,
noopDir, transformedDir, timestamp *regexp.Regexp) {
name := testcaseName name := testcaseName
testcase := DiffTestCase{} testcase := DiffTestCase{}
testcaseDir := filepath.Join("testdata", "testcase-"+name) testcaseDir := filepath.Join("testdata", "testcase-"+name)
@@ -119,6 +127,4 @@ func TestDiff(t *testing.T) {
ioutil.WriteFile(testcase.ExpectedDiff, actualBytes, 0644) ioutil.WriteFile(testcase.ExpectedDiff, actualBytes, 0644)
} }
})
}
} }