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