@@ -21,6 +21,7 @@ import (
21
21
"k8s.io/apimachinery/pkg/runtime/schema"
22
22
"sigs.k8s.io/cli-utils/pkg/apis/actuation"
23
23
"sigs.k8s.io/cli-utils/pkg/common"
24
+ "sigs.k8s.io/cli-utils/pkg/inventory"
24
25
"sigs.k8s.io/cli-utils/pkg/object"
25
26
)
26
27
@@ -74,9 +75,10 @@ var testPod = object.ObjMetadata{
74
75
75
76
func TestLoadStore (t * testing.T ) {
76
77
tests := map [string ]struct {
77
- inv * unstructured.Unstructured
78
- objs []object.ObjMetadata
79
- isError bool
78
+ inv * unstructured.Unstructured
79
+ objs []object.ObjMetadata
80
+ objStatus []actuation.ObjectStatus
81
+ isError bool
80
82
}{
81
83
"Nil inventory is error" : {
82
84
inv : nil ,
@@ -89,26 +91,68 @@ func TestLoadStore(t *testing.T) {
89
91
isError : false ,
90
92
},
91
93
"Simple test" : {
92
- inv : inventoryObj ,
93
- objs : []object.ObjMetadata {testPod },
94
+ inv : inventoryObj ,
95
+ objs : []object.ObjMetadata {testPod },
96
+ objStatus : []actuation.ObjectStatus {
97
+ {
98
+ ObjectReference : inventory .ObjectReferenceFromObjMetadata (testPod ),
99
+ Strategy : actuation .ActuationStrategyApply ,
100
+ Actuation : actuation .ActuationPending ,
101
+ Reconcile : actuation .ReconcilePending ,
102
+ },
103
+ },
94
104
isError : false ,
95
105
},
96
106
"Test two objects" : {
97
- inv : inventoryObj ,
98
- objs : []object.ObjMetadata {testDeployment , testService },
107
+ inv : inventoryObj ,
108
+ objs : []object.ObjMetadata {testDeployment , testService },
109
+ objStatus : []actuation.ObjectStatus {
110
+ {
111
+ ObjectReference : inventory .ObjectReferenceFromObjMetadata (testDeployment ),
112
+ Strategy : actuation .ActuationStrategyApply ,
113
+ Actuation : actuation .ActuationSucceeded ,
114
+ Reconcile : actuation .ReconcileSucceeded ,
115
+ },
116
+ {
117
+ ObjectReference : inventory .ObjectReferenceFromObjMetadata (testService ),
118
+ Strategy : actuation .ActuationStrategyApply ,
119
+ Actuation : actuation .ActuationSucceeded ,
120
+ Reconcile : actuation .ReconcileSucceeded ,
121
+ },
122
+ },
99
123
isError : false ,
100
124
},
101
125
"Test three objects" : {
102
- inv : inventoryObj ,
103
- objs : []object.ObjMetadata {testDeployment , testService , testPod },
126
+ inv : inventoryObj ,
127
+ objs : []object.ObjMetadata {testDeployment , testService , testPod },
128
+ objStatus : []actuation.ObjectStatus {
129
+ {
130
+ ObjectReference : inventory .ObjectReferenceFromObjMetadata (testDeployment ),
131
+ Strategy : actuation .ActuationStrategyApply ,
132
+ Actuation : actuation .ActuationSucceeded ,
133
+ Reconcile : actuation .ReconcileSucceeded ,
134
+ },
135
+ {
136
+ ObjectReference : inventory .ObjectReferenceFromObjMetadata (testService ),
137
+ Strategy : actuation .ActuationStrategyApply ,
138
+ Actuation : actuation .ActuationSucceeded ,
139
+ Reconcile : actuation .ReconcileSucceeded ,
140
+ },
141
+ {
142
+ ObjectReference : inventory .ObjectReferenceFromObjMetadata (testPod ),
143
+ Strategy : actuation .ActuationStrategyApply ,
144
+ Actuation : actuation .ActuationPending ,
145
+ Reconcile : actuation .ReconcilePending ,
146
+ },
147
+ },
104
148
isError : false ,
105
149
},
106
150
}
107
151
108
152
for name , tc := range tests {
109
153
t .Run (name , func (t * testing.T ) {
110
154
wrapped := WrapInventoryObj (tc .inv )
111
- _ = wrapped .Store (tc .objs , []actuation. ObjectStatus {} )
155
+ _ = wrapped .Store (tc .objs , tc . objStatus )
112
156
invStored , err := wrapped .GetObject ()
113
157
if tc .isError {
114
158
if err == nil {
@@ -129,6 +173,13 @@ func TestLoadStore(t *testing.T) {
129
173
if ! objs .Equal (tc .objs ) {
130
174
t .Fatalf ("expected inventory objs (%v), got (%v)" , tc .objs , objs )
131
175
}
176
+ resourceStatus , _ , err := unstructured .NestedSlice (invStored .Object , "status" , "resourceStatuses" )
177
+ if err != nil {
178
+ t .Fatalf ("unexpected error %v received" , err )
179
+ }
180
+ if len (resourceStatus ) != len (tc .objStatus ) {
181
+ t .Fatalf ("expected %d resource status but got %d" , len (tc .objStatus ), len (resourceStatus ))
182
+ }
132
183
})
133
184
}
134
185
}
0 commit comments