-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Variable Depths and improve regex (#118)
* Make the service path variable depth * Update validation to support . * Support different validation for CHAMBER_NO_PATHS * Add tests for validations
- Loading branch information
1 parent
46a6dcb
commit d9c77ea
Showing
5 changed files
with
210 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidations(t *testing.T) { | ||
|
||
// Test Key formats | ||
validKeyFormat := []string{ | ||
"foo", | ||
"foo.bar", | ||
"foo.", | ||
".foo", | ||
"foo-bar", | ||
} | ||
|
||
for _, k := range validKeyFormat { | ||
t.Run("Key validation should return Nil", func(t *testing.T) { | ||
result := validateKey(k) | ||
assert.Nil(t, result) | ||
}) | ||
} | ||
|
||
invalidKeyFormat := []string{ | ||
"/foo", | ||
"foo//bar", | ||
"foo/bar", | ||
} | ||
|
||
for _, k := range invalidKeyFormat { | ||
t.Run("Key validation should return Error", func(t *testing.T) { | ||
result := validateKey(k) | ||
assert.Error(t, result) | ||
}) | ||
} | ||
|
||
// Test Service format with PATH | ||
validServicePathFormat := []string{ | ||
"foo", | ||
"foo.", | ||
".foo", | ||
"foo.bar", | ||
"foo-bar", | ||
"foo/bar", | ||
"foo.bar/foo", | ||
"foo-bar/foo", | ||
"foo-bar/foo-bar", | ||
"foo/bar/foo", | ||
"foo/bar/foo-bar", | ||
} | ||
|
||
for _, k := range validServicePathFormat { | ||
t.Run("Service with PATH validation should return Nil", func(t *testing.T) { | ||
result := validateService(k) | ||
assert.Nil(t, result) | ||
}) | ||
} | ||
|
||
invalidServicePathFormat := []string{ | ||
"foo/", | ||
"/foo", | ||
"foo//bar", | ||
} | ||
|
||
for _, k := range invalidServicePathFormat { | ||
t.Run("Service with PATH validation should return Error", func(t *testing.T) { | ||
result := validateService(k) | ||
assert.Error(t, result) | ||
}) | ||
} | ||
|
||
// Test Service format without PATH | ||
os.Setenv("CHAMBER_NO_PATHS", "true") | ||
validServiceNoPathFormat := []string{ | ||
"foo", | ||
"foo.", | ||
".foo", | ||
"foo.bar", | ||
"foo-bar", | ||
"foo-bar.foo", | ||
"foo-bar.foo-bar", | ||
"foo.bar.foo", | ||
"foo.bar.foo-bar", | ||
} | ||
|
||
for _, k := range validServiceNoPathFormat { | ||
t.Run("Service without PATH validation should return Nil", func(t *testing.T) { | ||
result := validateService(k) | ||
assert.Nil(t, result) | ||
}) | ||
} | ||
|
||
invalidServiceNoPathFormat := []string{ | ||
"/foo", | ||
"foo//bar", | ||
"foo/bar", | ||
} | ||
|
||
for _, k := range invalidServiceNoPathFormat { | ||
t.Run("Service without PATH validation should return Error", func(t *testing.T) { | ||
result := validateService(k) | ||
assert.Error(t, result) | ||
}) | ||
} | ||
os.Unsetenv("CHAMBER_NO_PATHS") | ||
} |
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