@@ -17,7 +17,8 @@ limitations under the License.
1717package goosefs
1818
1919import (
20- "testing"
20+ . "github.com/onsi/ginkgo/v2"
21+ . "github.com/onsi/gomega"
2122
2223 datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2324 "github.com/fluid-cloudnative/fluid/pkg/ddc/base"
@@ -26,52 +27,60 @@ import (
2627 "sigs.k8s.io/controller-runtime/pkg/log/zap"
2728)
2829
29- func TestTransformFuse (t * testing.T ) {
30+ var _ = Describe ("TransformFuse" , func () {
31+ BeforeEach (func () {
32+ ctrl .SetLogger (zap .New (func (o * zap.Options ) {
33+ o .Development = true
34+ }))
35+ })
3036
31- var x int64 = 1000
32- ctrl .SetLogger (zap .New (func (o * zap.Options ) {
33- o .Development = true
34- }))
35-
36- var tests = []struct {
37+ type testCase struct {
3738 runtime * datav1alpha1.GooseFSRuntime
3839 dataset * datav1alpha1.Dataset
3940 value * GooseFS
4041 expect []string
41- }{
42- {& datav1alpha1.GooseFSRuntime {
43- Spec : datav1alpha1.GooseFSRuntimeSpec {
44- Fuse : datav1alpha1.GooseFSFuseSpec {},
45- },
46- }, & datav1alpha1.Dataset {
47- Spec : datav1alpha1.DatasetSpec {
48- Mounts : []datav1alpha1.Mount {{
49- MountPoint : "local:///mnt/test" ,
50- Name : "test" ,
51- }},
52- Owner : & datav1alpha1.User {
53- UID : & x ,
54- GID : & x ,
55- },
56- },
57- }, & GooseFS {}, []string {"fuse" , "--fuse-opts=rw,direct_io,uid=1000,gid=1000,allow_other" }},
58- }
59- for _ , test := range tests {
60- runtimeInfo , err := base .BuildRuntimeInfo ("test" , "fluid" , "goosefs" )
61- if err != nil {
62- t .Errorf ("fail to create the runtimeInfo with error %v" , err )
63- }
64- engine := & GooseFSEngine {
65- runtimeInfo : runtimeInfo ,
66- Client : fakeutils .NewFakeClientWithScheme (testScheme ),
67- }
68- engine .Log = ctrl .Log
69- err = engine .transformFuse (test .runtime , test .dataset , test .value )
70- if err != nil {
71- t .Errorf ("error %v" , err )
72- }
73- if test .value .Fuse .Args [1 ] != test .expect [1 ] {
74- t .Errorf ("expected %v, got %v" , test .expect , test .value .Fuse .Args )
75- }
7642 }
77- }
43+
44+ DescribeTable ("should transform fuse configuration correctly" ,
45+ func (tc testCase ) {
46+ runtimeInfo , err := base .BuildRuntimeInfo ("test" , "fluid" , "goosefs" )
47+ Expect (err ).NotTo (HaveOccurred ())
48+
49+ engine := & GooseFSEngine {
50+ runtimeInfo : runtimeInfo ,
51+ Client : fakeutils .NewFakeClientWithScheme (testScheme ),
52+ Log : ctrl .Log ,
53+ }
54+
55+ err = engine .transformFuse (tc .runtime , tc .dataset , tc .value )
56+ Expect (err ).NotTo (HaveOccurred ())
57+ Expect (tc .value .Fuse .Args ).To (Equal (tc .expect ))
58+ },
59+ Entry ("with owner UID and GID" ,
60+ func () testCase {
61+ var x int64 = 1000
62+ return testCase {
63+ runtime : & datav1alpha1.GooseFSRuntime {
64+ Spec : datav1alpha1.GooseFSRuntimeSpec {
65+ Fuse : datav1alpha1.GooseFSFuseSpec {},
66+ },
67+ },
68+ dataset : & datav1alpha1.Dataset {
69+ Spec : datav1alpha1.DatasetSpec {
70+ Mounts : []datav1alpha1.Mount {{
71+ MountPoint : "local:///mnt/test" ,
72+ Name : "test" ,
73+ }},
74+ Owner : & datav1alpha1.User {
75+ UID : & x ,
76+ GID : & x ,
77+ },
78+ },
79+ },
80+ value : & GooseFS {},
81+ expect : []string {"fuse" , "--fuse-opts=rw,direct_io,uid=1000,gid=1000,allow_other" },
82+ }
83+ }(),
84+ ),
85+ )
86+ })
0 commit comments