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
|
store secretstore.Store
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApp(_ ...any) *App {
|
func NewApp() *App {
|
||||||
return &App{}
|
return &App{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ func() *App = NewApp
|
||||||
|
|
||||||
func TestAppRunRejectsUnknownCommand(t *testing.T) {
|
func TestAppRunRejectsUnknownCommand(t *testing.T) {
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,33 @@ package secretstore
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestCredentialValidateRequiresAllFields(t *testing.T) {
|
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 {
|
for _, tt := range tests {
|
||||||
t.Fatal("expected validation error when password is missing")
|
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