-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable and hide deletion protection (#1052)
Signed-off-by: Jose Vazquez <[email protected]>
- Loading branch information
Showing
8 changed files
with
181 additions
and
55 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/version" | ||
) | ||
|
||
const ( | ||
nonReleaseVersion = "1.8.0-30-g81233c6-dirty" | ||
releaseVersion = "1.9.0-certified" | ||
) | ||
|
||
func TestDeletionProtectionDisabledByDefault(t *testing.T) { | ||
os.Unsetenv(objectDeletionProtectionEnvVar) | ||
os.Unsetenv(subobjectDeletionProtectionEnvVar) | ||
|
||
cfg := Config{ | ||
ObjectDeletionProtection: objectDeletionProtectionDefault, | ||
SubObjectDeletionProtection: subobjectDeletionProtectionDefault, | ||
} | ||
enableDeletionProtectionFromEnvVars(&cfg, version.DefaultVersion) | ||
|
||
assert.Equal(t, false, cfg.ObjectDeletionProtection) | ||
assert.Equal(t, false, cfg.SubObjectDeletionProtection) | ||
} | ||
|
||
func TestDeletionProtectionIgnoredOnReleases(t *testing.T) { | ||
version.Version = releaseVersion | ||
os.Setenv(objectDeletionProtectionEnvVar, "On") | ||
os.Setenv(subobjectDeletionProtectionEnvVar, "On") | ||
|
||
cfg := Config{ | ||
ObjectDeletionProtection: objectDeletionProtectionDefault, | ||
SubObjectDeletionProtection: subobjectDeletionProtectionDefault, | ||
} | ||
enableDeletionProtectionFromEnvVars(&cfg, releaseVersion) | ||
|
||
assert.Equal(t, false, cfg.ObjectDeletionProtection) | ||
assert.Equal(t, false, cfg.SubObjectDeletionProtection) | ||
} | ||
|
||
func TestDeletionProtectionEnabledAsEnvVars(t *testing.T) { | ||
testCases := []struct { | ||
title string | ||
objDelProtect bool | ||
subObjDelProtect bool | ||
}{ | ||
{ | ||
"both env vars set on non release version enables both protections", | ||
true, | ||
true, | ||
}, | ||
{ | ||
"obj env var set on non release version enables obj protection only", | ||
true, | ||
false, | ||
}, | ||
{ | ||
"subobj env var set on non release version enables subobj protection only", | ||
false, | ||
true, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.title, func(t *testing.T) { | ||
os.Unsetenv(objectDeletionProtectionEnvVar) | ||
os.Unsetenv(subobjectDeletionProtectionEnvVar) | ||
if tc.objDelProtect { | ||
os.Setenv(objectDeletionProtectionEnvVar, "On") | ||
} | ||
if tc.subObjDelProtect { | ||
os.Setenv(subobjectDeletionProtectionEnvVar, "On") | ||
} | ||
|
||
cfg := Config{ | ||
ObjectDeletionProtection: objectDeletionProtectionDefault, | ||
SubObjectDeletionProtection: subobjectDeletionProtectionDefault, | ||
} | ||
enableDeletionProtectionFromEnvVars(&cfg, nonReleaseVersion) | ||
|
||
assert.Equal(t, tc.objDelProtect, cfg.ObjectDeletionProtection) | ||
assert.Equal(t, tc.subObjDelProtect, cfg.SubObjectDeletionProtection) | ||
}) | ||
} | ||
} |
Submodule helm-charts
updated
6 files
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,16 @@ | ||
package version | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
const DefaultVersion = "unknown" | ||
|
||
// Version set by the linker during link time. | ||
var Version = "unknown" | ||
var Version = DefaultVersion | ||
|
||
func IsRelease(v string) bool { | ||
return v != DefaultVersion && | ||
regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+[-certified]*$`).Match([]byte(strings.TrimSpace(v))) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package version_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/version" | ||
) | ||
|
||
func TestReleaseVersion(t *testing.T) { | ||
testCases := []struct { | ||
title string | ||
version string | ||
expected bool | ||
}{ | ||
{ | ||
"default is not release", | ||
version.DefaultVersion, | ||
false, | ||
}, | ||
{ | ||
"empty is not release", | ||
"", | ||
false, | ||
}, | ||
{ | ||
"dirty is not release", | ||
"1.8.0-30-g81233c6-dirty", | ||
false, | ||
}, | ||
{ | ||
"semver IS release", | ||
"1.8.0", | ||
true, | ||
}, | ||
{ | ||
"semver certified IS release", | ||
"1.8.0-certified", | ||
true, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.title, func(t *testing.T) { | ||
assert.Equal(t, tc.expected, version.IsRelease(tc.version)) | ||
}) | ||
} | ||
} |
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