40 lines
901 B
Go
40 lines
901 B
Go
package config
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDeploymentConfigUsesDomainNames(t *testing.T) {
|
|
files, err := os.ReadDir(".")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, file := range files {
|
|
name := file.Name()
|
|
if file.IsDir() || !strings.HasSuffix(name, ".go") {
|
|
continue
|
|
}
|
|
if strings.HasPrefix(name, "current_") {
|
|
t.Errorf("%s retains an implementation-generation filename", name)
|
|
}
|
|
if strings.HasSuffix(name, "_test.go") {
|
|
continue
|
|
}
|
|
parsed, err := parser.ParseFile(token.NewFileSet(), name, nil, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ast.Inspect(parsed, func(node ast.Node) bool {
|
|
if declaration, ok := node.(*ast.FuncDecl); ok && strings.Contains(declaration.Name.Name, "Current") {
|
|
t.Errorf("%s retains an implementation-generation function %s", name, declaration.Name.Name)
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
}
|