Generate valid file Pod Names and test for them
Ensure that pods coming from the unit test configuration validate, and that proper names are generated. Lowercases source filenames, strips all but a-z0-9, and tests for consistent results.
This commit is contained in:
@@ -148,8 +148,8 @@ func TestExtractFromEmptyDir(t *testing.T) {
|
||||
|
||||
func TestExtractFromDir(t *testing.T) {
|
||||
manifests := []api.ContainerManifest{
|
||||
{ID: "", Containers: []api.Container{{Image: "foo"}}},
|
||||
{ID: "", Containers: []api.Container{{Image: "bar"}}},
|
||||
{Version: "v1beta1", Containers: []api.Container{{Name: "1", Image: "foo"}}},
|
||||
{Version: "v1beta1", Containers: []api.Container{{Name: "2", Image: "bar"}}},
|
||||
}
|
||||
files := make([]*os.File, len(manifests))
|
||||
|
||||
@@ -193,6 +193,32 @@ func TestExtractFromDir(t *testing.T) {
|
||||
if !reflect.DeepEqual(expected, update) {
|
||||
t.Errorf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
for i := range update.Pods {
|
||||
if errs := kubelet.ValidatePod(&update.Pods[i]); len(errs) != 0 {
|
||||
t.Errorf("Expected no validation errors on %#v, Got %#v", update.Pods[i], errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubdomainSafeName(t *testing.T) {
|
||||
type Case struct {
|
||||
Input string
|
||||
Expected string
|
||||
}
|
||||
testCases := []Case{
|
||||
{"/some/path/invalidUPPERCASE", "invaliduppercasa6hlenc0vpqbbdtt26ghneqsq3pvud"},
|
||||
{"/some/path/_-!%$#&@^&*(){}", "nvhc03p016m60huaiv3avts372rl2p"},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
value := simpleSubdomainSafeHash(testCase.Input)
|
||||
if value != testCase.Expected {
|
||||
t.Errorf("Expected %s, Got %s", testCase.Expected, value)
|
||||
}
|
||||
value2 := simpleSubdomainSafeHash(testCase.Input)
|
||||
if value != value2 {
|
||||
t.Errorf("Value for %s was not stable across runs: %s %s", testCase.Input, value, value2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// These are used for testing extract json (below)
|
||||
|
Reference in New Issue
Block a user