...
1
2
3
4 package status_test
5
6 import (
7 "strings"
8 "testing"
9
10 "github.com/stretchr/testify/assert"
11 "sigs.k8s.io/cli-utils/pkg/kstatus/polling/testutil"
12 "sigs.k8s.io/cli-utils/pkg/kstatus/status"
13 "sigs.k8s.io/yaml"
14 )
15
16 func TestExampleCompute(t *testing.T) {
17 deploymentManifest := `
18 apiVersion: apps/v1
19 kind: Deployment
20 metadata:
21 name: test
22 generation: 1
23 namespace: qual
24 status:
25 observedGeneration: 1
26 updatedReplicas: 1
27 readyReplicas: 1
28 availableReplicas: 1
29 replicas: 1
30 conditions:
31 - type: Progressing
32 status: "True"
33 reason: NewReplicaSetAvailable
34 - type: Available
35 status: "True"
36 `
37 deployment := testutil.YamlToUnstructured(t, deploymentManifest)
38
39 res, err := status.Compute(deployment)
40 assert.NoError(t, err)
41
42 assert.Equal(t, status.Status("Current"), res.Status)
43 }
44
45 func TestExampleAugment(t *testing.T) {
46 deploymentManifest := `
47 apiVersion: apps/v1
48 kind: Deployment
49 metadata:
50 name: test
51 generation: 1
52 namespace: qual
53 status:
54 observedGeneration: 1
55 updatedReplicas: 1
56 readyReplicas: 1
57 availableReplicas: 1
58 replicas: 1
59 conditions:
60 - type: Progressing
61 status: "True"
62 reason: NewReplicaSetAvailable
63 - type: Available
64 status: "True"
65 `
66 deployment := testutil.YamlToUnstructured(t, deploymentManifest)
67
68 err := status.Augment(deployment)
69 assert.NoError(t, err)
70
71 b, err := yaml.Marshal(deployment.Object)
72 assert.NoError(t, err)
73
74 receivedManifest := strings.TrimSpace(string(b))
75 expectedManifest := strings.TrimSpace(`
76 apiVersion: apps/v1
77 kind: Deployment
78 metadata:
79 generation: 1
80 name: test
81 namespace: qual
82 status:
83 availableReplicas: 1
84 conditions:
85 - reason: NewReplicaSetAvailable
86 status: "True"
87 type: Progressing
88 - status: "True"
89 type: Available
90 observedGeneration: 1
91 readyReplicas: 1
92 replicas: 1
93 updatedReplicas: 1
94 `)
95
96 assert.Equal(t, expectedManifest, receivedManifest)
97 }
98
View as plain text