Skip to content

Commit 4b3ffb4

Browse files
committed
test: add unit test
1 parent 46fb162 commit 4b3ffb4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pkg/smb/smb_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package smb
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"os"
2223
"path/filepath"
@@ -529,3 +530,30 @@ func createTestFile(path string) error {
529530

530531
return nil
531532
}
533+
534+
func TestGetUserNamePasswordFromSecret(t *testing.T) {
535+
tests := []struct {
536+
desc string
537+
secretName string
538+
secretNamespace string
539+
expectedUsername string
540+
expectedPassword string
541+
expectedDomain string
542+
expectedError error
543+
}{
544+
{
545+
desc: "kubeclient is nil",
546+
secretName: "secretName",
547+
expectedError: fmt.Errorf("could not username and password from secret(secretName): KubeClient is nil"),
548+
},
549+
}
550+
551+
d := NewFakeDriver()
552+
for _, test := range tests {
553+
username, password, domain, err := d.GetUserNamePasswordFromSecret(context.Background(), test.secretName, test.secretNamespace)
554+
assert.Equal(t, test.expectedUsername, username, "test[%s]: unexpected username", test.desc)
555+
assert.Equal(t, test.expectedPassword, password, "test[%s]: unexpected password", test.desc)
556+
assert.Equal(t, test.expectedDomain, domain, "test[%s]: unexpected domain", test.desc)
557+
assert.Equal(t, test.expectedError, err, "test[%s]: unexpected error", test.desc)
558+
}
559+
}

0 commit comments

Comments
 (0)