-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add config-spec-hash annotation to manifestwork
Signed-off-by: haoqing0110 <[email protected]>
- Loading branch information
1 parent
613d134
commit cca7df9
Showing
36 changed files
with
1,441 additions
and
588 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
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
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 |
---|---|---|
@@ -1 +1,78 @@ | ||
package agentdeploy | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1" | ||
workapiv1 "open-cluster-management.io/api/work/v1" | ||
) | ||
|
||
func TestConfigsToAnnotations(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
configReference []addonapiv1alpha1.ConfigReference | ||
expectAnnotations map[string]string | ||
}{ | ||
{ | ||
name: "generate annotaions", | ||
configReference: []addonapiv1alpha1.ConfigReference{ | ||
{ | ||
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{ | ||
Group: "addon.open-cluster-management.io", | ||
Resource: "addondeploymentconfigs", | ||
}, | ||
DesiredConfig: &addonapiv1alpha1.ConfigSpecHash{ | ||
ConfigReferent: addonapiv1alpha1.ConfigReferent{ | ||
Name: "test", | ||
Namespace: "open-cluster-management", | ||
}, | ||
SpecHash: "hash1", | ||
}, | ||
}, | ||
{ | ||
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{ | ||
Resource: "addonhubconfigs", | ||
}, | ||
DesiredConfig: &addonapiv1alpha1.ConfigSpecHash{ | ||
ConfigReferent: addonapiv1alpha1.ConfigReferent{ | ||
Name: "test", | ||
}, | ||
SpecHash: "hash2", | ||
}, | ||
}, | ||
}, | ||
expectAnnotations: map[string]string{ | ||
workapiv1.ManifestConfigSpecHashAnnotationKey: `{"addondeploymentconfigs.addon.open-cluster-management.io/open-cluster-management/test":"hash1","addonhubconfigs//test":"hash2"}`}, | ||
}, | ||
{ | ||
name: "generate annotaions without configReference", | ||
configReference: []addonapiv1alpha1.ConfigReference{}, | ||
expectAnnotations: nil, | ||
}, | ||
{ | ||
name: "generate annotaions without DesiredConfig", | ||
configReference: []addonapiv1alpha1.ConfigReference{ | ||
{ | ||
ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{ | ||
Group: "addon.open-cluster-management.io", | ||
Resource: "addondeploymentconfigs", | ||
}, | ||
}, | ||
}, | ||
expectAnnotations: map[string]string{ | ||
workapiv1.ManifestConfigSpecHashAnnotationKey: `{}`}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
annotations, err := configsToAnnotations(c.configReference) | ||
assert.NoError(t, err) | ||
if !reflect.DeepEqual(annotations, c.expectAnnotations) { | ||
t.Fatalf("Expected annotations to be equal but got %v (expected) and %v (actual)", c.expectAnnotations, annotations) | ||
} | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.