@@ -35,7 +35,7 @@ func TestCreateAccessPoint(t *testing.T) {
35
35
testFunc func (t * testing.T )
36
36
}{
37
37
{
38
- name : "Success - AP does not exist " ,
38
+ name : "Success" ,
39
39
testFunc : func (t * testing.T ) {
40
40
mockCtl := gomock .NewController (t )
41
41
mockEfs := mocks .NewMockEfs (mockCtl )
@@ -74,63 +74,9 @@ func TestCreateAccessPoint(t *testing.T) {
74
74
},
75
75
}
76
76
77
- describeAPOutput := & efs.DescribeAccessPointsOutput {
78
- AccessPoints : nil ,
79
- }
80
-
81
77
ctx := context .Background ()
82
- mockEfs .EXPECT ().DescribeAccessPointsWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (describeAPOutput , nil )
83
78
mockEfs .EXPECT ().CreateAccessPointWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (output , nil )
84
- res , err := c .CreateAccessPoint (ctx , clientToken , req , true )
85
-
86
- if err != nil {
87
- t .Fatalf ("CreateAccessPointFailed is failed: %v" , err )
88
- }
89
-
90
- if res == nil {
91
- t .Fatal ("Result is nil" )
92
- }
93
-
94
- if accessPointId != res .AccessPointId {
95
- t .Fatalf ("AccessPointId mismatched. Expected: %v, Actual: %v" , accessPointId , res .AccessPointId )
96
- }
97
-
98
- if fsId != res .FileSystemId {
99
- t .Fatalf ("FileSystemId mismatched. Expected: %v, Actual: %v" , fsId , res .FileSystemId )
100
- }
101
- mockCtl .Finish ()
102
- },
103
- },
104
- {
105
- name : "Success - AP already exists" ,
106
- testFunc : func (t * testing.T ) {
107
- mockCtl := gomock .NewController (t )
108
- mockEfs := mocks .NewMockEfs (mockCtl )
109
- c := & cloud {
110
- efs : mockEfs ,
111
- }
112
-
113
- tags := make (map [string ]string )
114
- tags ["cluster" ] = "efs"
115
-
116
- req := & AccessPointOptions {
117
- FileSystemId : fsId ,
118
- Uid : uid ,
119
- Gid : gid ,
120
- DirectoryPerms : directoryPerms ,
121
- DirectoryPath : directoryPath ,
122
- Tags : tags ,
123
- }
124
-
125
- describeAPOutput := & efs.DescribeAccessPointsOutput {
126
- AccessPoints : []* efs.AccessPointDescription {
127
- {AccessPointId : aws .String (accessPointId ), FileSystemId : aws .String (fsId ), ClientToken : aws .String (clientToken ), RootDirectory : & efs.RootDirectory {Path : aws .String (directoryPath )}, Tags : []* efs.Tag {{Key : aws .String (PvcNameTagKey ), Value : aws .String (volName )}}},
128
- },
129
- }
130
-
131
- ctx := context .Background ()
132
- mockEfs .EXPECT ().DescribeAccessPointsWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (describeAPOutput , nil )
133
- res , err := c .CreateAccessPoint (ctx , clientToken , req , true )
79
+ res , err := c .CreateAccessPoint (ctx , clientToken , req )
134
80
135
81
if err != nil {
136
82
t .Fatalf ("CreateAccessPointFailed is failed: %v" , err )
@@ -164,14 +110,10 @@ func TestCreateAccessPoint(t *testing.T) {
164
110
DirectoryPerms : directoryPerms ,
165
111
DirectoryPath : directoryPath ,
166
112
}
167
- describeAPOutput := & efs.DescribeAccessPointsOutput {
168
- AccessPoints : nil ,
169
- }
170
113
171
114
ctx := context .Background ()
172
- mockEfs .EXPECT ().DescribeAccessPointsWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (describeAPOutput , nil )
173
115
mockEfs .EXPECT ().CreateAccessPointWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (nil , errors .New ("CreateAccessPointWithContext failed" ))
174
- _ , err := c .CreateAccessPoint (ctx , clientToken , req , true )
116
+ _ , err := c .CreateAccessPoint (ctx , clientToken , req )
175
117
if err == nil {
176
118
t .Fatalf ("CreateAccessPoint did not fail" )
177
119
}
@@ -195,7 +137,7 @@ func TestCreateAccessPoint(t *testing.T) {
195
137
196
138
ctx := context .Background ()
197
139
mockEfs .EXPECT ().CreateAccessPointWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (nil , awserr .New (AccessDeniedException , "Access Denied" , errors .New ("Access Denied" )))
198
- _ , err := c .CreateAccessPoint (ctx , clientToken , req , false )
140
+ _ , err := c .CreateAccessPoint (ctx , clientToken , req )
199
141
if err == nil {
200
142
t .Fatalf ("CreateAccessPoint did not fail" )
201
143
}
@@ -551,6 +493,119 @@ func TestDescribeAccessPoint(t *testing.T) {
551
493
}
552
494
}
553
495
496
+ func TestFindAccessPointByClientToken (t * testing.T ) {
497
+ var (
498
+ fsId = "fs-abcd1234"
499
+ accessPointId = "ap-abc123"
500
+ clientToken = "token"
501
+ path = "/myDir"
502
+ Gid int64 = 1000
503
+ Uid int64 = 1000
504
+ )
505
+ testCases := []struct {
506
+ name string
507
+ testFunc func (t * testing.T )
508
+ }{
509
+ {
510
+ name : "Success - clientToken found" ,
511
+ testFunc : func (t * testing.T ) {
512
+ mockctl := gomock .NewController (t )
513
+ mockEfs := mocks .NewMockEfs (mockctl )
514
+ c := & cloud {efs : mockEfs }
515
+
516
+ output := & efs.DescribeAccessPointsOutput {
517
+ AccessPoints : []* efs.AccessPointDescription {
518
+ {
519
+ AccessPointId : aws .String (accessPointId ),
520
+ FileSystemId : aws .String (fsId ),
521
+ ClientToken : aws .String (clientToken ),
522
+ RootDirectory : & efs.RootDirectory {
523
+ Path : aws .String (path ),
524
+ },
525
+ PosixUser : & efs.PosixUser {
526
+ Gid : aws .Int64 (Gid ),
527
+ Uid : aws .Int64 (Uid ),
528
+ },
529
+ },
530
+ },
531
+ NextToken : nil ,
532
+ }
533
+
534
+ ctx := context .Background ()
535
+ mockEfs .EXPECT ().DescribeAccessPointsWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (output , nil )
536
+ res , err := c .FindAccessPointByClientToken (ctx , clientToken , fsId )
537
+ if err != nil {
538
+ t .Fatalf ("Find Access Point by Client Token failed: %v" , err )
539
+ }
540
+
541
+ if res == nil {
542
+ t .Fatal ("Result is nil" )
543
+ }
544
+
545
+ mockctl .Finish ()
546
+ },
547
+ },
548
+ {
549
+ name : "Success - nil result if clientToken is not found" ,
550
+ testFunc : func (t * testing.T ) {
551
+ mockctl := gomock .NewController (t )
552
+ mockEfs := mocks .NewMockEfs (mockctl )
553
+ c := & cloud {efs : mockEfs }
554
+
555
+ output := & efs.DescribeAccessPointsOutput {
556
+ AccessPoints : []* efs.AccessPointDescription {
557
+ {
558
+ AccessPointId : aws .String (accessPointId ),
559
+ FileSystemId : aws .String (fsId ),
560
+ ClientToken : aws .String ("differentToken" ),
561
+ RootDirectory : & efs.RootDirectory {
562
+ Path : aws .String (path ),
563
+ },
564
+ PosixUser : & efs.PosixUser {
565
+ Gid : aws .Int64 (Gid ),
566
+ Uid : aws .Int64 (Uid ),
567
+ },
568
+ },
569
+ },
570
+ NextToken : nil ,
571
+ }
572
+
573
+ ctx := context .Background ()
574
+ mockEfs .EXPECT ().DescribeAccessPointsWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (output , nil )
575
+ res , err := c .FindAccessPointByClientToken (ctx , clientToken , fsId )
576
+ if err != nil {
577
+ t .Fatalf ("Find Access Point by Client Token failed: %v" , err )
578
+ }
579
+
580
+ if res != nil {
581
+ t .Fatal ("Result should be nil. No access point with the specified token" )
582
+ }
583
+
584
+ mockctl .Finish ()
585
+ },
586
+ },
587
+ {
588
+ name : "Fail - Access Denied" ,
589
+ testFunc : func (t * testing.T ) {
590
+ mockctl := gomock .NewController (t )
591
+ mockEfs := mocks .NewMockEfs (mockctl )
592
+ c := & cloud {efs : mockEfs }
593
+ ctx := context .Background ()
594
+ mockEfs .EXPECT ().DescribeAccessPointsWithContext (gomock .Eq (ctx ), gomock .Any ()).Return (nil , awserr .New (AccessDeniedException , "Access Denied" , errors .New ("Access Denied" )))
595
+ _ , err := c .FindAccessPointByClientToken (ctx , clientToken , fsId )
596
+ if err == nil {
597
+ t .Fatalf ("Find Access Point by Client Token should have failed: %v" , err )
598
+ }
599
+
600
+ mockctl .Finish ()
601
+ },
602
+ },
603
+ }
604
+ for _ , tc := range testCases {
605
+ t .Run (tc .name , tc .testFunc )
606
+ }
607
+ }
608
+
554
609
func TestListAccessPoints (t * testing.T ) {
555
610
var (
556
611
fsId = "fs-abcd1234"
@@ -1024,7 +1079,7 @@ func Test_findAccessPointByPath(t *testing.T) {
1024
1079
tt .prepare (mockEfs )
1025
1080
}
1026
1081
1027
- gotAccessPoint , err := c .findAccessPointByClientToken (ctx , tt .args .clientToken , tt .args .accessPointOpts )
1082
+ gotAccessPoint , err := c .FindAccessPointByClientToken (ctx , tt .args .clientToken , tt .args .accessPointOpts . FileSystemId )
1028
1083
if (err != nil ) != tt .wantErr {
1029
1084
t .Errorf ("findAccessPointByClientToken() error = %v, wantErr %v" , err , tt .wantErr )
1030
1085
return
0 commit comments