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

Match preview versions in google_composer_environment regex #4797

Merged
merged 2 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
const (
composerEnvironmentEnvVariablesRegexp = "[a-zA-Z_][a-zA-Z0-9_]*."
composerEnvironmentReservedAirflowEnvVarRegexp = "AIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+"
composerEnvironmentVersionRegexp = `composer-([0-9]+\.[0-9]+\.[0-9]+|latest)-airflow-([0-9]+\.[0-9]+(\.[0-9]+.*)?)`
composerEnvironmentVersionRegexp = `composer-([0-9]+\.[0-9]+\.[0-9]+(-preview.[0-9]+)?|latest)-airflow-([0-9]+\.[0-9]+(\.[0-9]+.*)?)`
)

var composerEnvironmentReservedEnvVar = map[string]struct{}{
Expand Down Expand Up @@ -1540,7 +1540,7 @@ func composerImageVersionDiffSuppress(_, old, new string, _ *schema.ResourceData
versionRe := regexp.MustCompile(composerEnvironmentVersionRegexp)
oldVersions := versionRe.FindStringSubmatch(old)
newVersions := versionRe.FindStringSubmatch(new)
if oldVersions == nil || len(oldVersions) < 3 {
if oldVersions == nil || len(oldVersions) < 4 {
// Somehow one of the versions didn't match the regexp or didn't
// have values in the capturing groups. In that case, fall back to
// an equality check.
Expand All @@ -1557,7 +1557,7 @@ func composerImageVersionDiffSuppress(_, old, new string, _ *schema.ResourceData

// Check airflow version using the version package to account for
// diffs like 1.10 and 1.10.0
eq, err := versionsEqual(oldVersions[2], newVersions[2])
eq, err := versionsEqual(oldVersions[3], newVersions[3])
if err != nil {
log.Printf("[WARN] Could not parse airflow version, %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func TestComposerImageVersionDiffSuppress(t *testing.T) {
{"new latest", "composer-1.4.1-airflow-1.10.0", "composer-latest-airflow-1.10.0", true},
{"airflow equivalent", "composer-1.4.0-airflow-1.10.0", "composer-1.4.0-airflow-1.10", true},
{"airflow different", "composer-1.4.0-airflow-1.10.0", "composer-1.4-airflow-1.9.0", false},
{"airflow different composer latest", "composer-1.4.0-airflow-1.10.0", "composer-latest-airflow-1.9.0", false},
{"preview matches", "composer-1.17.0-preview.0-airflow-2.0.1", "composer-1.17.0-preview.0-airflow-2.0.1", true},
}

for _, tc := range cases {
if actual := composerImageVersionDiffSuppress("", tc.old, tc.new, nil); actual != tc.expected {
t.Fatalf("'%s' failed, expected %v but got %v", tc.name, tc.expected, actual)
t.Errorf("'%s' failed, expected %v but got %v", tc.name, tc.expected, actual)
}
}
}
Expand Down