mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Feat: add policy parser test (#4174)
Signed-off-by: huiwq1990 <huiwq1990@163.com>
This commit is contained in:
@@ -204,6 +204,32 @@ spec:
|
||||
cmd?: [...string]
|
||||
}`
|
||||
|
||||
const policyDefinition = `
|
||||
# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
|
||||
# Definition source cue file: vela-templates/definitions/internal/topology.cue
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: PolicyDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: Determining the destination where components should be deployed to.
|
||||
name: topology
|
||||
namespace: {{ include "systemDefinitionNamespace" . }}
|
||||
spec:
|
||||
schematic:
|
||||
cue:
|
||||
template: |
|
||||
parameter: {
|
||||
// +usage=Specify the names of the clusters to select.
|
||||
cluster?: [...string]
|
||||
// +usage=Specify the label selector for clusters
|
||||
clusterLabelSelector?: [string]: string
|
||||
// +usage=Deprecated: Use clusterLabelSelector instead.
|
||||
clusterSelector?: [string]: string
|
||||
// +usage=Specify the target namespace to deploy in the selected clusters, default inherit the original namespace.
|
||||
namespace?: string
|
||||
}
|
||||
`
|
||||
|
||||
const appfileYaml = `
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
@@ -268,6 +294,12 @@ var _ = Describe("Test application parser", func() {
|
||||
return err
|
||||
}
|
||||
*o = *td
|
||||
case *v1beta1.PolicyDefinition:
|
||||
ppd, err := util.UnMarshalStringToPolicyDefinition(policyDefinition)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*o = *ppd
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -190,6 +190,19 @@ func UnMarshalStringToTraitDefinition(s string) (*v1beta1.TraitDefinition, error
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
// UnMarshalStringToPolicyDefinition parse a string to a policyDefinition object
|
||||
func UnMarshalStringToPolicyDefinition(s string) (*v1beta1.PolicyDefinition, error) {
|
||||
obj := &v1beta1.PolicyDefinition{}
|
||||
_body, err := yaml.YAMLToJSON([]byte(s))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := json.Unmarshal(_body, obj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
// CheckAppRevision check if appRevision list is right
|
||||
func CheckAppRevision(revs []v1beta1.ApplicationRevision, collection []int) (bool, error) {
|
||||
if len(revs) != len(collection) {
|
||||
|
||||
Reference in New Issue
Block a user