@@ -20,7 +20,7 @@ import (
2020 smbapi "github.com/kubernetes-csi/csi-proxy/pkg/smb/api"
2121)
2222
23- func TestSmb (t * testing.T ) {
23+ func TestSMB (t * testing.T ) {
2424 fsClient , err := fs .New (fsapi .New ())
2525 require .Nil (t , err )
2626 client , err := smb .New (smbapi .New (), fsClient )
@@ -34,45 +34,45 @@ func TestSmb(t *testing.T) {
3434 localPath := fmt .Sprintf ("C:\\ localpath%s" , randomString (5 ))
3535
3636 if err = setupUser (username , password ); err != nil {
37- t .Fatalf ("TestSmbAPIGroup %v" , err )
37+ t .Fatalf ("TestSMBAPIGroup %v" , err )
3838 }
3939 defer removeUser (t , username )
4040
41- if err = setupSmbShare (smbShare , sharePath , username ); err != nil {
42- t .Fatalf ("TestSmbAPIGroup %v" , err )
41+ if err = setupSMBShare (smbShare , sharePath , username ); err != nil {
42+ t .Fatalf ("TestSMBAPIGroup %v" , err )
4343 }
44- defer removeSmbShare (t , smbShare )
44+ defer removeSMBShare (t , smbShare )
4545
4646 hostname , err := os .Hostname ()
4747 assert .Nil (t , err )
4848
4949 username = "domain\\ " + username
5050 remotePath := "\\ \\ " + hostname + "\\ " + smbShare
5151 // simulate Mount SMB operations around staging a volume on a node
52- mountSmbShareReq := & smb.NewSmbGlobalMappingRequest {
52+ mountSMBShareReq := & smb.NewSMBGlobalMappingRequest {
5353 RemotePath : remotePath ,
5454 Username : username ,
5555 Password : password ,
5656 }
57- _ , err = client .NewSmbGlobalMapping (context .Background (), mountSmbShareReq )
57+ _ , err = client .NewSMBGlobalMapping (context .Background (), mountSMBShareReq )
5858 if err != nil {
59- t .Fatalf ("TestSmbAPIGroup %v" , err )
59+ t .Fatalf ("TestSMBAPIGroup %v" , err )
6060 }
6161
62- err = getSmbGlobalMapping (remotePath )
62+ err = getSMBGlobalMapping (remotePath )
6363 assert .Nil (t , err )
6464
6565 err = writeReadFile (remotePath )
6666 assert .Nil (t , err )
6767
68- unmountSmbShareReq := & smb.RemoveSmbGlobalMappingRequest {
68+ unmountSMBShareReq := & smb.RemoveSMBGlobalMappingRequest {
6969 RemotePath : remotePath ,
7070 }
71- _ , err = client .RemoveSmbGlobalMapping (context .Background (), unmountSmbShareReq )
71+ _ , err = client .RemoveSMBGlobalMapping (context .Background (), unmountSMBShareReq )
7272 if err != nil {
73- t .Fatalf ("TestSmbAPIGroup %v" , err )
73+ t .Fatalf ("TestSMBAPIGroup %v" , err )
7474 }
75- err = getSmbGlobalMapping (remotePath )
75+ err = getSMBGlobalMapping (remotePath )
7676 assert .NotNil (t , err )
7777 err = writeReadFile (localPath )
7878 assert .NotNil (t , err )
@@ -118,9 +118,9 @@ func removeUser(t *testing.T, username string) {
118118 }
119119}
120120
121- func setupSmbShare (shareName , localPath , username string ) error {
121+ func setupSMBShare (shareName , localPath , username string ) error {
122122 if err := os .MkdirAll (localPath , 0755 ); err != nil {
123- return fmt .Errorf ("setupSmbShare failed to create local path %q: %v" , localPath , err )
123+ return fmt .Errorf ("setupSMBShare failed to create local path %q: %v" , localPath , err )
124124 }
125125 cmdLine := fmt .Sprintf (`New-SMBShare -Name $Env:sharename -Path $Env:path -fullaccess $Env:username` )
126126 cmd := exec .Command ("powershell" , "/c" , cmdLine )
@@ -129,37 +129,37 @@ func setupSmbShare(shareName, localPath, username string) error {
129129 fmt .Sprintf ("path=%s" , localPath ),
130130 fmt .Sprintf ("username=%s" , username ))
131131 if output , err := cmd .CombinedOutput (); err != nil {
132- return fmt .Errorf ("setupSmbShare failed: %v, output: %q" , err , string (output ))
132+ return fmt .Errorf ("setupSMBShare failed: %v, output: %q" , err , string (output ))
133133 }
134134
135135 return nil
136136}
137137
138- func removeSmbShare (t * testing.T , shareName string ) {
138+ func removeSMBShare (t * testing.T , shareName string ) {
139139 cmdLine := fmt .Sprintf (`Remove-SMBShare -Name $Env:sharename -Force` )
140140 cmd := exec .Command ("powershell" , "/c" , cmdLine )
141141 cmd .Env = append (os .Environ (),
142142 fmt .Sprintf ("sharename=%s" , shareName ))
143143 if output , err := cmd .CombinedOutput (); err != nil {
144- t .Fatalf ("setupSmbShare failed: %v, output: %q" , err , string (output ))
144+ t .Fatalf ("setupSMBShare failed: %v, output: %q" , err , string (output ))
145145 }
146146 return
147147}
148148
149- func getSmbGlobalMapping (remotePath string ) error {
149+ func getSMBGlobalMapping (remotePath string ) error {
150150 // use PowerShell Environment Variables to store user input string to prevent command line injection
151151 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-5.1
152- cmdLine := fmt .Sprintf (`(Get-SmbGlobalMapping -RemotePath $Env:smbremotepath).Status` )
152+ cmdLine := fmt .Sprintf (`(Get-SMBGlobalMapping -RemotePath $Env:smbremotepath).Status` )
153153
154154 cmd := exec .Command ("powershell" , "/c" , cmdLine )
155155 cmd .Env = append (os .Environ (),
156156 fmt .Sprintf ("smbremotepath=%s" , remotePath ))
157157 output , err := cmd .CombinedOutput ()
158158 if err != nil {
159- return fmt .Errorf ("Get-SmbGlobalMapping failed: %v, output: %q" , err , string (output ))
159+ return fmt .Errorf ("Get-SMBGlobalMapping failed: %v, output: %q" , err , string (output ))
160160 }
161161 if ! strings .Contains (string (output ), "OK" ) {
162- return fmt .Errorf ("Get-SmbGlobalMapping return status %q instead of OK" , string (output ))
162+ return fmt .Errorf ("Get-SMBGlobalMapping return status %q instead of OK" , string (output ))
163163 }
164164 return nil
165165}
0 commit comments