Skip to content

Commit

Permalink
Merge pull request #867 from lcarva/EC-346
Browse files Browse the repository at this point in the history
Do not require pre-built ec binary
  • Loading branch information
lcarva authored Jan 18, 2024
2 parents a202d99 + b57fb09 commit b42581e
Show file tree
Hide file tree
Showing 5 changed files with 2,252 additions and 27 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ public/
node_modules/
.cache/
*.swp
coverage.json
/acceptance/bin/ec
coverage.json
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ update-bundles: ## Push policy bundles to quay.io and generate infra-deployments

.PHONY: acceptance
acceptance: ## Run acceptance tests
@go build -o acceptance/bin/ec github.com/enterprise-contract/ec-cli
@cd acceptance && go test ./...

#--------------------------------------------------------------------
49 changes: 31 additions & 18 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"testing"

"github.com/cucumber/godog"
// Neded so the "go run" command can execute.
_ "github.com/enterprise-contract/ec-cli/cmd"
)

const (
Expand All @@ -28,13 +30,13 @@ var sampleGCPolicyInput string
type testStateKey struct{}

type testState struct {
tempDir string
variables map[string]string
cmd *exec.Cmd
report report
cliPath string
inputFileName string
configFileName string
tempDir string
variables map[string]string
report report
cliPath string
inputFileName string
configFileName string
acceptanceModulePath string
}

// Types used for parsing violations and warnings from report
Expand Down Expand Up @@ -109,11 +111,18 @@ func validateInputWithPolicyConfig(ctx context.Context) (context.Context, error)
}

cmd := exec.Command(
ts.cliPath, "validate", "input",
"--file", ts.inputFileName,
"--policy", ts.configFileName,
"--strict=false")
cmd.Dir = ts.tempDir
"go",
"run",
"github.com/enterprise-contract/ec-cli",
"validate",
"input",
"--file",
ts.inputFileName,
"--policy",
ts.configFileName,
"--strict=false",
)
cmd.Dir = ts.acceptanceModulePath

var stdout bytes.Buffer
var stderr bytes.Buffer
Expand All @@ -124,8 +133,6 @@ func validateInputWithPolicyConfig(ctx context.Context) (context.Context, error)
return ctx, fmt.Errorf("running ec validate input: %w\n%s", err, stderr.String())
}

ts.cmd = cmd

var r report
if err := json.Unmarshal(stdout.Bytes(), &r); err != nil {
return ctx, fmt.Errorf("unmarshalling report: %w", err)
Expand Down Expand Up @@ -187,16 +194,22 @@ func setupScenario(ctx context.Context, sc *godog.Scenario) (context.Context, er
return ctx, fmt.Errorf("setting up scenario: %w", err)
}

acceptanceModulePath, err := filepath.Abs(".")
if err != nil {
return ctx, fmt.Errorf("getting acceptance module path: %w", err)
}

gitroot, err := filepath.Abs("..")
if err != nil {
return ctx, fmt.Errorf("getting gitroot: %w", err)
}

ts := testState{
cliPath: filepath.Join(gitroot, "acceptance/bin/ec"),
tempDir: tempDir,
inputFileName: path.Join(tempDir, policyInputFilename),
configFileName: path.Join(tempDir, policyConfigFilename),
cliPath: filepath.Join(gitroot, "acceptance/bin/ec"),
tempDir: tempDir,
acceptanceModulePath: acceptanceModulePath,
inputFileName: path.Join(tempDir, policyInputFilename),
configFileName: path.Join(tempDir, policyConfigFilename),
variables: map[string]string{
"GITROOT": gitroot,
},
Expand Down
Loading

0 comments on commit b42581e

Please sign in to comment.