aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2020-01-28 15:47:28 +0000
committerGravatar GitHub <noreply@github.com> 2020-01-28 15:47:28 +0000
commit40d0fd8598e6d8c824491ba9cb5119c9f07b56d6 (patch)
treef9d4a3582fbc34cb6500f6e97cd5a4aaf057e65a
parent04292f1375f5d22abdfbe9fec962e3357ea416ac (diff)
downloadcoredns-40d0fd8598e6d8c824491ba9cb5119c9f07b56d6.tar.gz
coredns-40d0fd8598e6d8c824491ba9cb5119c9f07b56d6.tar.zst
coredns-40d0fd8598e6d8c824491ba9cb5119c9f07b56d6.zip
presubmit tests (#3630)
* presubmit tests Rename the test file to presubmit_test.go Remove println from previous merge. Add filename hyphen check Remove the shell presubmit file that did this before Signed-off-by: Miek Gieben <miek@miek.nl> * remove Signed-off-by: Miek Gieben <miek@miek.nl>
-rwxr-xr-x.presubmit/filename-hyphen10
-rw-r--r--test/presubmit_test.go (renamed from test/trailing_test.go)29
2 files changed, 28 insertions, 11 deletions
diff --git a/.presubmit/filename-hyphen b/.presubmit/filename-hyphen
deleted file mode 100755
index de66a06c7..000000000
--- a/.presubmit/filename-hyphen
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-
-echo "** presubmit/$(basename $0)"
-
-for dir in "$@"; do
- if find $dir | grep '-'; then
- echo "** presubmit/$(basename $0): please use an underscore in filenames instead of a hyphen"
- exit 1
- fi
-done
diff --git a/test/trailing_test.go b/test/presubmit_test.go
index e4490df23..392cbe5fb 100644
--- a/test/trailing_test.go
+++ b/test/presubmit_test.go
@@ -1,5 +1,7 @@
package test
+// These tests check for meta level items, like trailing whitespace, correct file naming etc.
+
import (
"bufio"
"fmt"
@@ -30,7 +32,6 @@ func hasTrailingWhitespace(path string, info os.FileInfo, _ error) error {
return nil
}
- println("looking at", path)
file, err := os.Open(path)
if err != nil {
return nil
@@ -48,3 +49,29 @@ func hasTrailingWhitespace(path string, info os.FileInfo, _ error) error {
return scanner.Err()
}
+
+func TestFileNameHyphen(t *testing.T) {
+ err := filepath.Walk("..", hasHyphen)
+ if err != nil {
+ t.Fatal(err)
+ }
+}
+
+func hasHyphen(path string, info os.FileInfo, _ error) error {
+ // only for regular files, not starting with a . and those that are go files.
+ if !info.Mode().IsRegular() {
+ return nil
+ }
+ if strings.HasPrefix(path, "../.") {
+ return nil
+ }
+ if filepath.Ext(path) != ".go" {
+ return nil
+ }
+
+ if strings.Index(path, "-") > 0 {
+ return fmt.Errorf("file %q has a hyphen, please use underscores in file names", path)
+ }
+
+ return nil
+}