Skip to content
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

refactor: e2e test ensure conftest command to check conftest version is greater or equal to specific version #2812

Conversation

krrrr38
Copy link
Contributor

@krrrr38 krrrr38 commented Dec 18, 2022

what

why

Based on #2807 (comment) discussion, we want to remove e2e controller version specific conftest command like

// Will fail test if conftest isn't in path and isn't version >= 0.25.0
func ensureRunningConftest(t *testing.T) {
localPath, err := exec.LookPath(fmt.Sprintf("conftest%s", ConftestVersion))
if err != nil {
t.Logf("conftest >= %s must be installed to run this test", ConftestVersion)
t.FailNow()
}
.

This version specific dependency is hard to upgrade conftest automatically.

To remove version dependency, I want remove conftest$version command.

references

@krrrr38 krrrr38 requested a review from a team as a code owner December 18, 2022 05:35
if err != nil {
t.Logf("conftest >= %s must be installed to run this test", ConftestVersion)
t.Logf("conftest must be installed to run this test")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version is greater than or equal logic is already implemented. so just remove conftest$version command dependency using conftest command.

// Will fail test if conftest isn't in path and isn't version >= 0.25.0
func ensureRunningConftest(t *testing.T) {
localPath, err := exec.LookPath(fmt.Sprintf("conftest%s", ConftestVersion))
if err != nil {
t.Logf("conftest >= %s must be installed to run this test", ConftestVersion)
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.FailNow()
}
}

@krrrr38 krrrr38 force-pushed the refactor-e2e-test-check-conftest-less-version branch from edd505e to 0f15273 Compare December 18, 2022 05:47
@krrrr38 krrrr38 force-pushed the refactor-e2e-test-check-conftest-less-version branch from 0f15273 to 558ff33 Compare December 18, 2022 08:37
@nitrocode nitrocode merged commit 063bbb9 into runatlantis:main Dec 18, 2022
@nitrocode
Copy link
Member

Nice job! This will make conftest upgrades much easier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants