-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* check for spec changes before metadata ones, and add a comment explaining why. * add a unit test for `hashOfResourceStruct`. Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
- Loading branch information
Showing
2 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
pkg/operator/resource/resourceapply/resource_cache_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package resourceapply | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"testing" | ||
) | ||
|
||
func TestHashOfResourceStructUnstructured(t *testing.T) { | ||
unstructuredObject := unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"kind": "Service", | ||
"apiVersion": "v1", | ||
"metadata": map[string]interface{}{ | ||
"name": "svc1", | ||
"namespace": "ns1", | ||
}, | ||
"spec": map[string]interface{}{ | ||
"selector": map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
"ports": []map[string]interface{}{ | ||
{ | ||
"protocol": "TCP", | ||
"port": 80, | ||
"targetPort": 9376, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
hash := hashOfResourceStruct(&unstructuredObject) | ||
unstructuredObject.Object["spec"].(map[string]interface{})["selector"].(map[string]interface{})["foo"] = "baz" | ||
if hashOfResourceStruct(&unstructuredObject) == hash { | ||
t.Errorf("expected a different hash after modifying the object") | ||
} | ||
} |