This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EVEREST-855 Namespaces validation improvements (#299)
EVEREST-855 ns validation improvements (cherry picked from commit 5ab6e5f)
- Loading branch information
1 parent
a408944
commit 6e9d1d2
Showing
9 changed files
with
200 additions
and
59 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package install | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidateNamespaces(t *testing.T) { | ||
t.Parallel() | ||
|
||
type tcase struct { | ||
name string | ||
input string | ||
output []string | ||
error error | ||
} | ||
|
||
tcases := []tcase{ | ||
{ | ||
name: "empty string", | ||
input: "", | ||
output: nil, | ||
error: ErrNSEmpty, | ||
}, | ||
{ | ||
name: "several empty strings", | ||
input: " , ,", | ||
output: nil, | ||
error: ErrNSEmpty, | ||
}, | ||
{ | ||
name: "correct", | ||
input: "aaa,bbb,ccc", | ||
output: []string{"aaa", "bbb", "ccc"}, | ||
error: nil, | ||
}, | ||
{ | ||
name: "correct with spaces", | ||
input: ` aaa, bbb | ||
,ccc `, | ||
output: []string{"aaa", "bbb", "ccc"}, | ||
error: nil, | ||
}, | ||
{ | ||
name: "reserved system ns", | ||
input: "everest-system", | ||
output: nil, | ||
error: ErrNSReserved("everest-system"), | ||
}, | ||
{ | ||
name: "reserved system ns and empty ns", | ||
input: "everest-system, ", | ||
output: nil, | ||
error: ErrNSReserved("everest-system"), | ||
}, | ||
{ | ||
name: "reserved monitoring ns", | ||
input: "everest-monitoring", | ||
output: nil, | ||
error: ErrNSReserved("everest-monitoring"), | ||
}, | ||
{ | ||
name: "duplicated ns", | ||
input: "aaa,bbb,aaa", | ||
output: []string{"aaa", "bbb"}, | ||
error: nil, | ||
}, | ||
{ | ||
name: "name is too long", | ||
input: "e1234567890123456789012345678901234567890123456789012345678901234567890,bbb", | ||
output: nil, | ||
error: ErrNameNotRFC1035Compatible("e1234567890123456789012345678901234567890123456789012345678901234567890"), | ||
}, | ||
{ | ||
name: "name starts with number", | ||
input: "1aaa,bbb", | ||
output: nil, | ||
error: ErrNameNotRFC1035Compatible("1aaa"), | ||
}, | ||
{ | ||
name: "name contains special characters", | ||
input: "aa12a,b$s", | ||
output: nil, | ||
error: ErrNameNotRFC1035Compatible("b$s"), | ||
}, | ||
} | ||
|
||
for _, tc := range tcases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
output, err := ValidateNamespaces(tc.input) | ||
assert.Equal(t, tc.error, err) | ||
assert.ElementsMatch(t, tc.output, output) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.