32 lines
1011 B
Go
32 lines
1011 B
Go
package handlers
|
|
|
|
import (
|
|
"git.mchus.pro/mchus/quoteforge/internal/localdb"
|
|
"testing"
|
|
)
|
|
|
|
func TestSetupPassword(t *testing.T) {
|
|
saved := &localdb.ConnectionSettings{Host: "db.example", Port: 3306, User: "example", PasswordEncrypted: "example"}
|
|
for _, tt := range []struct {
|
|
name, host, user, password string
|
|
port int
|
|
wantError bool
|
|
}{
|
|
{"same destination", "db.example", "example", "", 3306, false},
|
|
{"changed host", "other.example", "example", "", 3306, true},
|
|
{"changed port", "db.example", "example", "", 3307, true},
|
|
{"changed user", "db.example", "other", "", 3306, true},
|
|
{"explicit password", "other.example", "other", "example", 3307, false},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := setupPassword(saved, tt.host, tt.port, tt.user, tt.password)
|
|
if (err != nil) != tt.wantError {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if !tt.wantError && got != "example" {
|
|
t.Fatal("credential not preserved")
|
|
}
|
|
})
|
|
}
|
|
}
|