mirror of https://github.com/k3s-io/k3s
add test for validation NFS and GlusterFS
parent
ee0de5f376
commit
c5121d9e6f
|
@ -897,6 +897,98 @@ func TestValidateKeyToPath(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestValidateNFSVolumeSource(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
nfs *api.NFSVolumeSource
|
||||
errtype field.ErrorType
|
||||
errfield string
|
||||
errdetail string
|
||||
}{
|
||||
{
|
||||
name: "missing server",
|
||||
nfs: &api.NFSVolumeSource{Server: "", Path: "/tmp"},
|
||||
errtype: field.ErrorTypeRequired,
|
||||
errfield: "server",
|
||||
},
|
||||
{
|
||||
name: "missing path",
|
||||
nfs: &api.NFSVolumeSource{Server: "my-server", Path: ""},
|
||||
errtype: field.ErrorTypeRequired,
|
||||
errfield: "path",
|
||||
},
|
||||
{
|
||||
name: "abs path",
|
||||
nfs: &api.NFSVolumeSource{Server: "my-server", Path: "tmp"},
|
||||
errtype: field.ErrorTypeInvalid,
|
||||
errfield: "path",
|
||||
errdetail: "must be an absolute path",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
errs := validateNFSVolumeSource(tc.nfs, field.NewPath("field"))
|
||||
|
||||
if len(errs) > 0 && tc.errtype == "" {
|
||||
t.Errorf("[%d: %q] unexpected error(s): %v", i, tc.name, errs)
|
||||
} else if len(errs) == 0 && tc.errtype != "" {
|
||||
t.Errorf("[%d: %q] expected error type %v", i, tc.name, tc.errtype)
|
||||
} else if len(errs) >= 1 {
|
||||
if errs[0].Type != tc.errtype {
|
||||
t.Errorf("[%d: %q] expected error type %v, got %v", i, tc.name, tc.errtype, errs[0].Type)
|
||||
} else if !strings.HasSuffix(errs[0].Field, "."+tc.errfield) {
|
||||
t.Errorf("[%d: %q] expected error on field %q, got %q", i, tc.name, tc.errfield, errs[0].Field)
|
||||
} else if !strings.Contains(errs[0].Detail, tc.errdetail) {
|
||||
t.Errorf("[%d: %q] expected error detail %q, got %q", i, tc.name, tc.errdetail, errs[0].Detail)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateGlusterfs(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
gfs *api.GlusterfsVolumeSource
|
||||
errtype field.ErrorType
|
||||
errfield string
|
||||
}{
|
||||
{
|
||||
name: "missing endpointname",
|
||||
gfs: &api.GlusterfsVolumeSource{EndpointsName: "", Path: "/tmp"},
|
||||
errtype: field.ErrorTypeRequired,
|
||||
errfield: "endpoints",
|
||||
},
|
||||
{
|
||||
name: "missing path",
|
||||
gfs: &api.GlusterfsVolumeSource{EndpointsName: "my-endpoint", Path: ""},
|
||||
errtype: field.ErrorTypeRequired,
|
||||
errfield: "path",
|
||||
},
|
||||
{
|
||||
name: "missing endpintname and path",
|
||||
gfs: &api.GlusterfsVolumeSource{EndpointsName: "", Path: ""},
|
||||
errtype: field.ErrorTypeRequired,
|
||||
errfield: "endpoints",
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
errs := validateGlusterfs(tc.gfs, field.NewPath("field"))
|
||||
|
||||
if len(errs) > 0 && tc.errtype == "" {
|
||||
t.Errorf("[%d: %q] unexpected error(s): %v", i, tc.name, errs)
|
||||
} else if len(errs) == 0 && tc.errtype != "" {
|
||||
t.Errorf("[%d: %q] expected error type %v", i, tc.name, tc.errtype)
|
||||
} else if len(errs) >= 1 {
|
||||
if errs[0].Type != tc.errtype {
|
||||
t.Errorf("[%d: %q] expected error type %v, got %v", i, tc.name, tc.errtype, errs[0].Type)
|
||||
} else if !strings.HasSuffix(errs[0].Field, "."+tc.errfield) {
|
||||
t.Errorf("[%d: %q] expected error on field %q, got %q", i, tc.name, tc.errfield, errs[0].Field)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper
|
||||
func newInt32(val int) *int32 {
|
||||
p := new(int32)
|
||||
|
@ -9217,7 +9309,7 @@ func TestValidateEndpoints(t *testing.T) {
|
|||
|
||||
func TestValidateTLSSecret(t *testing.T) {
|
||||
successCases := map[string]api.Secret{
|
||||
"emtpy certificate chain": {
|
||||
"empty certificate chain": {
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "tls-cert", Namespace: "namespace"},
|
||||
Data: map[string][]byte{
|
||||
api.TLSCertKey: []byte("public key"),
|
||||
|
|
Loading…
Reference in New Issue