From e63e67178a68237eed74503151ef0cb1faa63907 Mon Sep 17 00:00:00 2001 From: thibaud-leclere Date: Fri, 10 Apr 2026 09:54:38 +0200 Subject: [PATCH] fix: tighten task 2 constructor contract --- internal/cli/app.go | 2 +- internal/cli/app_test.go | 2 ++ internal/secretstore/store_test.go | 30 +++++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/internal/cli/app.go b/internal/cli/app.go index 21a5e1e..0b58d50 100644 --- a/internal/cli/app.go +++ b/internal/cli/app.go @@ -10,7 +10,7 @@ type App struct { store secretstore.Store } -func NewApp(_ ...any) *App { +func NewApp() *App { return &App{} } diff --git a/internal/cli/app_test.go b/internal/cli/app_test.go index 3af3df8..19b263a 100644 --- a/internal/cli/app_test.go +++ b/internal/cli/app_test.go @@ -5,6 +5,8 @@ import ( "testing" ) +var _ func() *App = NewApp + func TestAppRunRejectsUnknownCommand(t *testing.T) { app := NewApp() diff --git a/internal/secretstore/store_test.go b/internal/secretstore/store_test.go index 4ac06df..0ffc95d 100644 --- a/internal/secretstore/store_test.go +++ b/internal/secretstore/store_test.go @@ -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") + } + }) } }