-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: e2e test to use conftest command instead version-specific command #2851
Merged
nitrocode
merged 1 commit into
runatlantis:main
from
krrrr38:refactor-e2e-no-conftest-version-dependency
Dec 22, 2022
+38
−47
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,9 @@ import ( | |
. "github.com/runatlantis/atlantis/testing" | ||
) | ||
|
||
const ConftestVersion = "0.36.0" // renovate: datasource=github-releases depName=open-policy-agent/conftest | ||
// In the e2e test, we use `conftest` not `conftest$version`. | ||
// Because if depends on the version, we need to upgrade test base image before e2e fix it. | ||
const conftestCommand = "conftest" | ||
|
||
var applyLocker locking.ApplyLocker | ||
var userConfig server.UserConfig | ||
|
@@ -64,8 +66,8 @@ func (m *NoopTFDownloader) GetAny(dst, src string, opts ...getter.ClientOption) | |
type LocalConftestCache struct { | ||
} | ||
|
||
func (m *LocalConftestCache) Get(key *version.Version) (string, error) { | ||
return exec.LookPath(fmt.Sprintf("conftest%s", ConftestVersion)) | ||
func (m *LocalConftestCache) Get(_ *version.Version) (string, error) { | ||
return exec.LookPath(conftestCommand) | ||
} | ||
|
||
func TestGitHubWorkflow(t *testing.T) { | ||
|
@@ -886,13 +888,6 @@ func setupE2E(t *testing.T, repoDir, repoConfigFile string) (events_controllers. | |
allowForkPRs := false | ||
dataDir, binDir, cacheDir := mkSubDirs(t) | ||
|
||
//env vars | ||
|
||
if userConfig.EnablePolicyChecksFlag { | ||
// need this to be set or we'll fail the policy check step | ||
os.Setenv(policy.DefaultConftestVersionEnvKey, "0.25.0") | ||
} | ||
|
||
// Mocks. | ||
e2eVCSClient := vcsmocks.NewMockClient() | ||
e2eStatusUpdater := &events.DefaultCommitStatusUpdater{Client: e2eVCSClient} | ||
|
@@ -1016,16 +1011,14 @@ func setupE2E(t *testing.T, repoDir, repoConfigFile string) (events_controllers. | |
|
||
Ok(t, err) | ||
|
||
conftestVersion, _ := version.NewVersion(ConftestVersion) | ||
|
||
conftextExec := policy.NewConfTestExecutorWorkflow(logger, binDir, &NoopTFDownloader{}) | ||
|
||
// swapping out version cache to something that always returns local contest | ||
// binary | ||
conftextExec.VersionCache = &LocalConftestCache{} | ||
|
||
policyCheckRunner, err := runtime.NewPolicyCheckStepRunner( | ||
conftestVersion, | ||
defaultTFVersion, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asis impl is invalid. |
||
conftextExec, | ||
) | ||
|
||
|
@@ -1392,30 +1385,16 @@ func mkSubDirs(t *testing.T) (string, string, string) { | |
return tmp, binDir, cachedir | ||
} | ||
|
||
// Will fail test if conftest isn't in path or is version less than specific version | ||
// Will fail test if conftest isn't in path | ||
func ensureRunningConftest(t *testing.T) { | ||
localPath, err := exec.LookPath("conftest") | ||
// use `conftest` command instead `contest$version`, so tests may fail on the environment cause the output logs may become change by version. | ||
t.Logf("conftest check may fail depends on conftest version. please use latest stable conftest.") | ||
_, err := exec.LookPath(conftestCommand) | ||
if err != nil { | ||
t.Logf("conftest must be installed to run this test") | ||
t.FailNow() | ||
} | ||
versionOutBytes, err := exec.Command(localPath, "--version").Output() // #nosec | ||
if err != nil { | ||
t.Logf("error running conftest version: %s", err) | ||
t.FailNow() | ||
} | ||
versionOutput := string(versionOutBytes) | ||
match := versionConftestRegex.FindStringSubmatch(versionOutput) | ||
if len(match) <= 1 { | ||
t.Logf("could not parse conftest version from %s", versionOutput) | ||
t.FailNow() | ||
} | ||
localVersion, err := version.NewVersion(match[1]) | ||
Ok(t, err) | ||
minVersion, err := version.NewVersion(ConftestVersion) | ||
Ok(t, err) | ||
if localVersion.LessThan(minVersion) { | ||
t.Logf("must have contest version >= %s, you have %s", minVersion, localVersion) | ||
t.Logf(`%s must be installed to run this test | ||
- on local, please install contest command or run 'make docker/test-all' | ||
- on CI, please check testing-env docker image contains conftest command. see testing/Dockerfile | ||
`, conftestCommand) | ||
t.FailNow() | ||
} | ||
} | ||
|
@@ -1456,10 +1435,3 @@ func ensureRunning014(t *testing.T) { | |
// Terraform v0.11.10 | ||
// => 0.11.10 | ||
var versionRegex = regexp.MustCompile("Terraform v(.*?)(\\s.*)?\n") | ||
|
||
/* | ||
* Newer versions will return both Conftest and OPA | ||
* Conftest: 0.35.0 | ||
* OPA: 0.45.0 | ||
*/ | ||
var versionConftestRegex = regexp.MustCompile("Conftest: (.*?)(\\s.*)?\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a main change in this PR. In e2e test, use
conftest
command.