Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Nov 22, 2022
1 parent 87b3c02 commit 4adb74e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/dev/podmandev/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ var (
},
})

volume = generator.GetVolumeComponent(generator.VolumeComponentParams{
Name: "myvolume",
})

basePod = &corev1.Pod{
TypeMeta: v1.TypeMeta{
APIVersion: "v1",
Expand Down Expand Up @@ -273,6 +277,45 @@ func Test_createPodFromComponent(t *testing.T) {
},
},
},
{
name: "basic component with volume mount",
args: args{
devfileObj: func() parser.DevfileObj {
data, _ := data.NewDevfileData(string(data.APISchemaVersion200))
_ = data.AddCommands([]v1alpha2.Command{command})
_ = data.AddComponents([]v1alpha2.Component{baseComponent, volume})
_ = data.AddVolumeMounts(baseComponent.Name, []v1alpha2.VolumeMount{
{
Name: volume.Name,
Path: "/path/to/mount",
},
})

return parser.DevfileObj{
Data: data,
}
},
componentName: devfileName,
appName: appName,
},
wantPod: func() *corev1.Pod {
pod := basePod.DeepCopy()
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{
Name: volume.Name,
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "odo-projects-" + devfileName + "-" + appName + "-" + volume.Name,
},
},
})
pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
Name: volume.Name,
MountPath: "/path/to/mount",
})
return pod
},
},

// TODO: Add test cases.
}
for _, tt := range tests {
Expand Down
14 changes: 14 additions & 0 deletions pkg/libdevfile/generator/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,17 @@ func GetOpenshiftComponent(params OpenshiftComponentParams) v1alpha2.Component {
}
return cmp
}

type VolumeComponentParams struct {
Name string
}

func GetVolumeComponent(params VolumeComponentParams) v1alpha2.Component {
cmp := v1alpha2.Component{
Name: params.Name,
ComponentUnion: v1alpha2.ComponentUnion{
Volume: &v1alpha2.VolumeComponent{},
},
}
return cmp
}

0 comments on commit 4adb74e

Please sign in to comment.