-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_test.go
More file actions
40 lines (35 loc) · 976 Bytes
/
auth_test.go
File metadata and controls
40 lines (35 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"testing"
)
func TestAuthCredentialsValidation(t *testing.T) {
tests := []struct {
name string
username string
password string
expectError bool
}{
{"valid credentials", "testuser", "testpass", false},
{"empty username", "", "password", true},
{"empty password", "username", "", true},
{"both empty", "", "", false}, // No auth mode - valid
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// We can't directly call the main function, so we'll test the logic
// by checking if both username and password are provided together
// This mimics the validation in main.go
hasUser := tt.username != ""
hasPass := tt.password != ""
if hasUser != hasPass {
if !tt.expectError {
t.Errorf("Expected no error for %s, but got validation error", tt.name)
}
} else {
if tt.expectError {
t.Errorf("Expected error for %s, but got no error", tt.name)
}
}
})
}
}