@@ -15,7 +15,8 @@ limitations under the License.
1515package goosefs
1616
1717import (
18- "testing"
18+ . "github.com/onsi/ginkgo/v2"
19+ . "github.com/onsi/gomega"
1920
2021 datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2122 "github.com/fluid-cloudnative/fluid/pkg/common"
@@ -28,13 +29,13 @@ import (
2829 "sigs.k8s.io/controller-runtime/pkg/client"
2930)
3031
31- func newGooseEngineRT (client client.Client , name string , namespace string , withRuntimeInfo bool , unittest bool ) * GooseFSEngine {
32+ func newGooseEngineRT (c client.Client , name string , namespace string , withRuntimeInfo bool , unittest bool ) * GooseFSEngine {
3233 runTimeInfo , _ := base .BuildRuntimeInfo (name , namespace , common .GooseFSRuntime )
3334 engine := & GooseFSEngine {
3435 runtime : & datav1alpha1.GooseFSRuntime {},
3536 name : name ,
3637 namespace : namespace ,
37- Client : client ,
38+ Client : c ,
3839 runtimeInfo : nil ,
3940 UnitTest : unittest ,
4041 Log : fake .NullLogger (),
@@ -46,124 +47,140 @@ func newGooseEngineRT(client client.Client, name string, namespace string, withR
4647 return engine
4748}
4849
49- func TestGetRuntimeInfo (t * testing.T ) {
50- runtimeInputs := []* datav1alpha1.GooseFSRuntime {
51- {
52- ObjectMeta : metav1.ObjectMeta {
53- Name : "hbase" ,
54- Namespace : "fluid" ,
55- },
56- Spec : datav1alpha1.GooseFSRuntimeSpec {
57- Fuse : datav1alpha1.GooseFSFuseSpec {},
58- },
59- },
60- {
61- ObjectMeta : metav1.ObjectMeta {
62- Name : "hadoop" ,
63- Namespace : "fluid" ,
64- },
65- Spec : datav1alpha1.GooseFSRuntimeSpec {
66- Fuse : datav1alpha1.GooseFSFuseSpec {},
67- },
68- },
69- }
70- daemonSetInputs := []* v1.DaemonSet {
71- {
72- ObjectMeta : metav1.ObjectMeta {
73- Name : "hbase-worker" ,
74- Namespace : "fluid" ,
50+ var _ = Describe ("GetRuntimeInfo" , func () {
51+ var fakeClient client.Client
52+
53+ BeforeEach (func () {
54+ runtimeInputs := []* datav1alpha1.GooseFSRuntime {
55+ {
56+ ObjectMeta : metav1.ObjectMeta {
57+ Name : "hbase" ,
58+ Namespace : "fluid" ,
59+ },
60+ Spec : datav1alpha1.GooseFSRuntimeSpec {
61+ Fuse : datav1alpha1.GooseFSFuseSpec {},
62+ },
7563 },
76- Spec : v1.DaemonSetSpec {
77- Template : corev1.PodTemplateSpec {
78- Spec : corev1.PodSpec {NodeSelector : map [string ]string {"data.fluid.io/storage-fluid-hbase" : "selector" }},
64+ {
65+ ObjectMeta : metav1.ObjectMeta {
66+ Name : "hadoop" ,
67+ Namespace : "fluid" ,
68+ },
69+ Spec : datav1alpha1.GooseFSRuntimeSpec {
70+ Fuse : datav1alpha1.GooseFSFuseSpec {},
7971 },
8072 },
81- },
82- {
83- ObjectMeta : metav1.ObjectMeta {
84- Name : "hadoop-worker" ,
85- Namespace : "fluid" ,
73+ }
74+ daemonSetInputs := []* v1.DaemonSet {
75+ {
76+ ObjectMeta : metav1.ObjectMeta {
77+ Name : "hbase-worker" ,
78+ Namespace : "fluid" ,
79+ },
80+ Spec : v1.DaemonSetSpec {
81+ Template : corev1.PodTemplateSpec {
82+ Spec : corev1.PodSpec {NodeSelector : map [string ]string {"data.fluid.io/storage-fluid-hbase" : "selector" }},
83+ },
84+ },
8685 },
87- Spec : v1.DaemonSetSpec {
88- Template : corev1.PodTemplateSpec {
89- Spec : corev1.PodSpec {NodeSelector : map [string ]string {"data.fluid.io/storage-fluid-hadoop" : "selector" }},
86+ {
87+ ObjectMeta : metav1.ObjectMeta {
88+ Name : "hadoop-worker" ,
89+ Namespace : "fluid" ,
90+ },
91+ Spec : v1.DaemonSetSpec {
92+ Template : corev1.PodTemplateSpec {
93+ Spec : corev1.PodSpec {NodeSelector : map [string ]string {"data.fluid.io/storage-fluid-hadoop" : "selector" }},
94+ },
9095 },
9196 },
92- },
93- }
94- dataSetInputs := [] * datav1alpha1. Dataset {
95- {
96- ObjectMeta : metav1. ObjectMeta {
97- Name : "hadoop " ,
98- Namespace : "fluid" ,
97+ }
98+ dataSetInputs := [] * datav1alpha1. Dataset {
99+ {
100+ ObjectMeta : metav1. ObjectMeta {
101+ Name : "hadoop" ,
102+ Namespace : "fluid " ,
103+ } ,
99104 },
100- },
101- }
102- objs := []runtime.Object {}
103- for _ , runtimeInput := range runtimeInputs {
104- objs = append (objs , runtimeInput .DeepCopy ())
105- }
106- for _ , daemonSetInput := range daemonSetInputs {
107- objs = append (objs , daemonSetInput .DeepCopy ())
108- }
109- for _ , dataSetInput := range dataSetInputs {
110- objs = append (objs , dataSetInput .DeepCopy ())
111- }
112- //scheme := runtime.NewScheme()
113- //scheme.AddKnownTypes(v1.SchemeGroupVersion, daemonSetWithSelector)
114- //scheme.AddKnownTypes(v1alpha1.GroupVersion,runtimeInput)
115- fakeClient := fake .NewFakeClientWithScheme (testScheme , objs ... )
105+ }
106+ objs := []runtime.Object {}
107+ for _ , runtimeInput := range runtimeInputs {
108+ objs = append (objs , runtimeInput .DeepCopy ())
109+ }
110+ for _ , daemonSetInput := range daemonSetInputs {
111+ objs = append (objs , daemonSetInput .DeepCopy ())
112+ }
113+ for _ , dataSetInput := range dataSetInputs {
114+ objs = append (objs , dataSetInput .DeepCopy ())
115+ }
116+ fakeClient = fake .NewFakeClientWithScheme (testScheme , objs ... )
117+ })
116118
117- testCases := [] struct {
119+ type testCase struct {
118120 name string
119121 namespace string
120122 withRuntimeInfo bool
121123 unittest bool
122- isErr bool
123- isNil bool
124- }{
125- {
126- name : "hbase" ,
127- namespace : "fluid" ,
128- withRuntimeInfo : false ,
129- unittest : false ,
130- isErr : false ,
131- isNil : false ,
132- },
133- {
134- name : "hbase" ,
135- namespace : "fluid" ,
136- withRuntimeInfo : false ,
137- unittest : true ,
138- isErr : false ,
139- isNil : false ,
140- },
141- {
142- name : "hbase" ,
143- namespace : "fluid" ,
144- withRuntimeInfo : true ,
145- isErr : false ,
146- isNil : false ,
147- },
148- {
149- name : "hadoop" ,
150- namespace : "fluid" ,
151- withRuntimeInfo : false ,
152- unittest : false ,
153- isErr : false ,
154- isNil : false ,
155- },
156- }
157- for _ , testCase := range testCases {
158- engine := newGooseEngineRT (fakeClient , testCase .name , testCase .namespace , testCase .withRuntimeInfo , testCase .unittest )
159- runtimeInfo , err := engine .getRuntimeInfo ()
160- isNil := runtimeInfo == nil
161- isErr := err != nil
162- if isNil != testCase .isNil {
163- t .Errorf (" want %t, got %t" , testCase .isNil , isNil )
164- }
165- if isErr != testCase .isErr {
166- t .Errorf (" want %t, got %t" , testCase .isErr , isErr )
167- }
124+ expectErr bool
125+ expectNil bool
168126 }
169- }
127+
128+ DescribeTable ("should get runtime info correctly" ,
129+ func (tc testCase ) {
130+ engine := newGooseEngineRT (fakeClient , tc .name , tc .namespace , tc .withRuntimeInfo , tc .unittest )
131+ runtimeInfo , err := engine .getRuntimeInfo ()
132+
133+ if tc .expectErr {
134+ Expect (err ).To (HaveOccurred ())
135+ } else {
136+ Expect (err ).NotTo (HaveOccurred ())
137+ }
138+
139+ if tc .expectNil {
140+ Expect (runtimeInfo ).To (BeNil ())
141+ } else {
142+ Expect (runtimeInfo ).NotTo (BeNil ())
143+ }
144+ },
145+ Entry ("hbase without runtimeInfo, not unittest" ,
146+ testCase {
147+ name : "hbase" ,
148+ namespace : "fluid" ,
149+ withRuntimeInfo : false ,
150+ unittest : false ,
151+ expectErr : false ,
152+ expectNil : false ,
153+ },
154+ ),
155+ Entry ("hbase without runtimeInfo, unittest" ,
156+ testCase {
157+ name : "hbase" ,
158+ namespace : "fluid" ,
159+ withRuntimeInfo : false ,
160+ unittest : true ,
161+ expectErr : false ,
162+ expectNil : false ,
163+ },
164+ ),
165+ Entry ("hbase with runtimeInfo" ,
166+ testCase {
167+ name : "hbase" ,
168+ namespace : "fluid" ,
169+ withRuntimeInfo : true ,
170+ unittest : false ,
171+ expectErr : false ,
172+ expectNil : false ,
173+ },
174+ ),
175+ Entry ("hadoop without runtimeInfo" ,
176+ testCase {
177+ name : "hadoop" ,
178+ namespace : "fluid" ,
179+ withRuntimeInfo : false ,
180+ unittest : false ,
181+ expectErr : false ,
182+ expectNil : false ,
183+ },
184+ ),
185+ )
186+ })
0 commit comments