Skip to content

Commit

Permalink
use packr instead of go-bindata
Browse files Browse the repository at this point in the history
  • Loading branch information
lhitchon committed Nov 22, 2018
1 parent 0495b6a commit a57e4f6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
44 changes: 43 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ CLI_FILES = $(shell find cli linter assertion -name \*.go)
default: all

deps:
@echo "=== dependencies ==="
go get "github.com/golang/dep/cmd/dep"
go get "github.com/jteeuwen/go-bindata/..."
go get "golang.org/x/lint/golint"
go get "github.com/stretchr/testify/assert"
dep ensure -vendor-only
@dep ensure -vendor-only -v

gen:
@echo "=== generating ==="
@go get "github.com/gobuffalo/packr/..."
@go generate ./...

lint: gen
Expand Down
9 changes: 5 additions & 4 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/ghodss/yaml"
"github.com/gobuffalo/packr"
"github.com/stelligent/config-lint/assertion"
"github.com/stelligent/config-lint/linter"
)
Expand Down Expand Up @@ -81,7 +82,6 @@ type (
}
)

//go:generate go-bindata -pkg $GOPACKAGE -o assets.go assets/
func main() {

commandLineOptions := getCommandLineOptions()
Expand Down Expand Up @@ -131,7 +131,7 @@ func main() {
}
ruleSets = addExceptions(ruleSets, profileOptions.Exceptions)
if useTerraformBuiltInRules {
builtInRuleSet, err := loadBuiltInRuleSet("assets/terraform.yml")
builtInRuleSet, err := loadBuiltInRuleSet("terraform.yml")
if err != nil {
fmt.Printf("Failed to load built-in rules for Terraform: %v\n", err)
os.Exit(-1)
Expand Down Expand Up @@ -179,7 +179,7 @@ func categoryMatch(rule assertion.Rule, exception RuleException) bool {
}

func validateRules(filenames []string, w ReportWriter) (int, error) {
builtInRuleSet, err := loadBuiltInRuleSet("assets/lint-rules.yml")
builtInRuleSet, err := loadBuiltInRuleSet("lint-rules.yml")
if err != nil {
return -1, err
}
Expand Down Expand Up @@ -221,7 +221,8 @@ func yamlFilesOnly(filenames []string) []string {

func loadBuiltInRuleSet(name string) (assertion.RuleSet, error) {
emptyRuleSet := assertion.RuleSet{}
rulesContent, err := Asset(name)
box := packr.NewBox("./assets")
rulesContent, err := box.FindString(name)
if err != nil {
return emptyRuleSet, err
}
Expand Down
33 changes: 6 additions & 27 deletions cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func TestLoadTerraformRules(t *testing.T) {
_, err := loadBuiltInRuleSet("assets/terraform.yml")
_, err := loadBuiltInRuleSet("terraform.yml")
if err != nil {
t.Errorf("Cannot load built-in Terraform rules")
}
}

func TestLoadValidateRules(t *testing.T) {
_, err := loadBuiltInRuleSet("assets/lint-rules.yml")
_, err := loadBuiltInRuleSet("lint-rules.yml")
if err != nil {
t.Errorf("Cannot load built-in rules for -validate option")
}
Expand Down Expand Up @@ -93,13 +93,13 @@ func TestProfileExceptions(t *testing.T) {
}
}

func TestBuiltInTerraformRules(t *testing.T) {
ruleSet, err := loadBuiltInRuleSet("assets/lint-rules.yml")
func TestBuiltRules(t *testing.T) {
ruleSet, err := loadBuiltInRuleSet("lint-rules.yml")
if err != nil {
t.Errorf("Expecting loadBuiltInRulesSet to not return error: %s", err.Error())
}
vs := assertion.StandardValueSource{}
filenames := []string{"assets/terraform.yml"}
filenames := []string{"assets/terraform.yml", "assets/lint-rules.yml"}
l, err := linter.NewLinter(ruleSet, vs, filenames)
if err != nil {
t.Errorf("Expecting NewLinter to not return error: %s", err.Error())
Expand All @@ -114,27 +114,6 @@ func TestBuiltInTerraformRules(t *testing.T) {
}
}

func TestBuiltInLinterRules(t *testing.T) {
ruleSet, err := loadBuiltInRuleSet("assets/lint-rules.yml")
if err != nil {
t.Errorf("Expecting loadBuiltInRulesSet to not return error: %s", err.Error())
}
vs := assertion.StandardValueSource{}
filenames := []string{"assets/lint-rules.yml"}
l, err := linter.NewLinter(ruleSet, vs, filenames)
if err != nil {
t.Errorf("Expecting NewLinter to not return error: %s", err.Error())
}
options := linter.Options{}
report, err := l.Validate(ruleSet, options)
if err != nil {
t.Errorf("Expecting Validate to not return error: %s", err.Error())
}
if len(report.Violations) != 0 {
t.Errorf("Expecting Validate for built in lint-rules to not report any violations: %v", report.Violations)
}
}

func TestPrintReport(t *testing.T) {
r := assertion.ValidationReport{}
var b bytes.Buffer
Expand Down Expand Up @@ -283,5 +262,5 @@ func TestArrayFlags(t *testing.T) {

func TestLoadBuiltInRuleSetMissing(t *testing.T) {
_, err := loadBuiltInRuleSet("missing.yml")
assert.Contains(t, err.Error(), "not found", "loadBuiltInRuleSet should fail for missing file")
assert.Contains(t, err.Error(), "no such file or directory", "loadBuiltInRuleSet should fail for missing file")
}
2 changes: 1 addition & 1 deletion cli/builtin_terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func numberOfFailures(violations []assertion.Violation) int {
}

func TestTerraformBuiltInRules(t *testing.T) {
ruleSet := loadRules(t, "assets/terraform.yml")
ruleSet := loadRules(t, "terraform.yml")
testCases := []BuiltInTestCase{
{"security-groups.tf", "SG_WORLD_INGRESS", 1, 0},
{"security-groups.tf", "SG_WORLD_EGRESS", 2, 0},
Expand Down

0 comments on commit a57e4f6

Please sign in to comment.