-
Notifications
You must be signed in to change notification settings - Fork 177
/
job_templates_test.go
71 lines (59 loc) · 1.97 KB
/
job_templates_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package storagecluster
import (
"context"
"testing"
openshiftv1 "github.com/openshift/api/template/v1"
api "github.com/red-hat-storage/ocs-operator/api/v1"
"github.com/stretchr/testify/assert"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)
func TestJobTemplates(t *testing.T) {
var cases = []struct {
jobTemplateName string
templateParameters []string
jobCmds []string
jobFunc func(*api.StorageCluster, string, []string) *batchv1.Job
}{
{
jobTemplateName: "ocs-osd-removal",
templateParameters: []string{"FAILED_OSD_IDS", "FORCE_OSD_REMOVAL"},
jobCmds: osdCleanupArgs,
jobFunc: newosdCleanUpJob,
},
{
jobTemplateName: "ocs-extend-cluster",
templateParameters: []string{"RECONFIGURE"},
jobCmds: extendClusterCommand,
jobFunc: newExtendClusterJob,
},
}
t, reconciler, cr, request := initStorageClusterResourceCreateUpdateTestWithPlatform(
t, nil, nil, nil)
for _, c := range cases {
template := &openshiftv1.Template{
ObjectMeta: metav1.ObjectMeta{
Name: c.jobTemplateName,
Namespace: cr.Namespace,
},
}
request.Name = c.jobTemplateName
err := reconciler.Client.Get(context.TODO(), request.NamespacedName, template)
assert.NoError(t, err)
for i, param := range c.templateParameters {
assert.Equal(t, param, template.Parameters[i].Name)
}
expectedJob := c.jobFunc(cr, c.jobTemplateName, c.jobCmds)
actualJob := &batchv1.Job{}
actualRaw := template.Objects[0].Raw
err = runtime.DecodeInto(unstructured.UnstructuredJSONScheme, actualRaw, actualJob)
assert.NoError(t, err)
assert.Equal(t, expectedJob, actualJob)
}
actualTemplateList := &openshiftv1.TemplateList{}
err := reconciler.Client.List(context.TODO(), actualTemplateList)
assert.NoError(t, err)
assert.Equal(t, len(cases), len(actualTemplateList.Items))
}