fix: tighten task 2 constructor contract
This commit is contained in:
parent
4ea1573dc8
commit
e63e67178a
3 changed files with 30 additions and 4 deletions
|
|
@ -10,7 +10,7 @@ type App struct {
|
|||
store secretstore.Store
|
||||
}
|
||||
|
||||
func NewApp(_ ...any) *App {
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
var _ func() *App = NewApp
|
||||
|
||||
func TestAppRunRejectsUnknownCommand(t *testing.T) {
|
||||
app := NewApp()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,33 @@ package secretstore
|
|||
import "testing"
|
||||
|
||||
func TestCredentialValidateRequiresAllFields(t *testing.T) {
|
||||
cred := Credential{Host: "imap.example.com", Username: "alice"}
|
||||
tests := []struct {
|
||||
name string
|
||||
cred Credential
|
||||
}{
|
||||
{
|
||||
name: "missing host",
|
||||
cred: Credential{Username: "alice", Password: "secret"},
|
||||
},
|
||||
{
|
||||
name: "missing username",
|
||||
cred: Credential{Host: "imap.example.com", Password: "secret"},
|
||||
},
|
||||
{
|
||||
name: "missing password",
|
||||
cred: Credential{Host: "imap.example.com", Username: "alice"},
|
||||
},
|
||||
{
|
||||
name: "whitespace only fields",
|
||||
cred: Credential{Host: " \t ", Username: "\n", Password: " "},
|
||||
},
|
||||
}
|
||||
|
||||
if err := cred.Validate(); err == nil {
|
||||
t.Fatal("expected validation error when password is missing")
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := tt.cred.Validate(); err == nil {
|
||||
t.Fatal("expected validation error when a required field is missing")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue