Skip to content

Commit

Permalink
add new component types to test utils (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-tsao committed Jun 15, 2021
1 parent edb6701 commit b0014e0
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/v200/utils/common/component_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func (devfile *TestDevfile) AddComponent(componentType schema.ComponentType) sch
if componentType == schema.ContainerComponentType {
component = devfile.createContainerComponent()
devfile.SetContainerComponentValues(&component)
} else if componentType == schema.KubernetesComponentType {
component = devfile.createKubernetesComponent()
devfile.SetK8sComponentValues(&component)
} else if componentType == schema.OpenshiftComponentType {
component = devfile.createOpenshiftComponent()
devfile.SetK8sComponentValues(&component)
} else if componentType == schema.VolumeComponentType {
component = devfile.createVolumeComponent()
devfile.SetVolumeComponentValues(&component)
Expand All @@ -63,6 +69,32 @@ func (devfile *TestDevfile) createContainerComponent() schema.Component {

}

// createKubernetesComponent creates a kubernetes component, ready for attribute setting
func (devfile *TestDevfile) createKubernetesComponent() schema.Component {

LogInfoMessage("Create a kubernetes component :")
component := schema.Component{}
component.Name = GetRandomUniqueString(8, true)
LogInfoMessage(fmt.Sprintf("....... Name: %s", component.Name))
component.Kubernetes = &schema.KubernetesComponent{}
devfile.componentAdded(component)
return component

}

// createOpenshiftComponent creates an openshift component, ready for attribute setting
func (devfile *TestDevfile) createOpenshiftComponent() schema.Component {

LogInfoMessage("Create an openshift component :")
component := schema.Component{}
component.Name = GetRandomUniqueString(8, true)
LogInfoMessage(fmt.Sprintf("....... Name: %s", component.Name))
component.Openshift = &schema.OpenshiftComponent{}
devfile.componentAdded(component)
return component

}

// createVolumeComponent creates a volume component , ready for attribute setting
func (devfile *TestDevfile) createVolumeComponent() schema.Component {

Expand Down Expand Up @@ -162,6 +194,39 @@ func (devfile *TestDevfile) SetContainerComponentValues(component *schema.Compon

}

func (devfile *TestDevfile) SetK8sComponentValues(component *schema.Component) {
var k8type *schema.K8sLikeComponent = &schema.K8sLikeComponent{}

if component.Kubernetes != nil {
k8type = &component.Kubernetes.K8sLikeComponent
} else if component.Openshift != nil {
k8type = &component.Openshift.K8sLikeComponent
}

if k8type.Inlined != "" {
k8type.Inlined = GetRandomString(GetRandomNumber(8, 18), false)
LogInfoMessage(fmt.Sprintf("....... updated k8type.Inlined: %s", k8type.Inlined))
} else if k8type.Uri != "" {
k8type.Uri = GetRandomString(GetRandomNumber(8, 18), false)
LogInfoMessage(fmt.Sprintf("....... updated k8type.Uri: %s", k8type.Uri))
} else {
//This is the component creation scenario when no inlined or uri property is set
if GetBinaryDecision() {
k8type.Inlined = GetRandomString(GetRandomNumber(8, 18), false)
LogInfoMessage(fmt.Sprintf("....... created Inlined: %s", k8type.Inlined))
} else {
k8type.Uri = GetRandomString(GetRandomNumber(8, 18), false)
LogInfoMessage(fmt.Sprintf("....... created Uri: %s", k8type.Uri))
}
}

if GetBinaryDecision() {
k8type.Endpoints = devfile.CreateEndpoints()
}

devfile.componentUpdated(*component)
}

// SetVolumeComponentValues randomly sets/updates volume component attributes to random values
func (devfile *TestDevfile) SetVolumeComponentValues(component *schema.Component) {

Expand Down

0 comments on commit b0014e0

Please sign in to comment.