...
1
16
17 package volumeattributesclass
18
19 import (
20 "testing"
21
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
24 "k8s.io/kubernetes/pkg/apis/storage"
25 )
26
27 func TestVolumeAttributesClassStrategy(t *testing.T) {
28 ctx := genericapirequest.NewDefaultContext()
29 if Strategy.NamespaceScoped() {
30 t.Errorf("VolumeAttributesClassStrategy must not be namespace scoped")
31 }
32 if Strategy.AllowCreateOnUpdate() {
33 t.Errorf("VolumeAttributesClassStrategy should not allow create on update")
34 }
35
36 class := &storage.VolumeAttributesClass{
37 ObjectMeta: metav1.ObjectMeta{
38 Name: "valid-class",
39 },
40 DriverName: "fake",
41 Parameters: map[string]string{
42 "foo": "bar",
43 },
44 }
45
46 Strategy.PrepareForCreate(ctx, class)
47
48 errs := Strategy.Validate(ctx, class)
49 if len(errs) != 0 {
50 t.Errorf("unexpected error validating %v", errs)
51 }
52
53 newClass := &storage.VolumeAttributesClass{
54 ObjectMeta: metav1.ObjectMeta{
55 Name: "valid-class-2",
56 ResourceVersion: "4",
57 },
58 DriverName: "fake",
59 Parameters: map[string]string{
60 "foo": "bar",
61 },
62 }
63
64 Strategy.PrepareForUpdate(ctx, newClass, class)
65
66 errs = Strategy.ValidateUpdate(ctx, newClass, class)
67 if len(errs) == 0 {
68 t.Errorf("Expected a validation error")
69 }
70 }
71
View as plain text