Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new component types to test utils #496

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking perhaps we don't need to split those component creation into sub function calls.
Those function call are almost identical, except for the part of creating an empty component.
can combine those sub function calls within this AddComponent

Suggested change
component = devfile.createKubernetesComponent()
func (devfile *TestDevfile) AddComponent(componentType schema.ComponentType) schema.Component {
LogInfoMessage("Create a %v component :", componentType)
component := schema.Component{}
component.Name = GetRandomUniqueString(8, true)
LogInfoMessage(fmt.Sprintf("....... Name: %s", component.Name))
switch componentType{
case schema.ContainerComponentType:
component.Container = &schema.ContainerComponent{}
devfile.SetContainerComponentValues(&component)
...... // cases for other component types
}
devfile.componentAdded(component)
return component
}

Same for AddCommand

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kim-tsao I guess I'm late for this PR..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangcao77 sorry I missed this! I appreciate your feedback anyhow so I'll try to apply your suggestion next time, thanks.

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