test: add unit tests for config generation and form values
Cover the deploy-critical pure logic: - GenerateConfigTOML: round-trip decode of values + a guard asserting the config port is always containerAppPort (host port must not leak) - GenerateWireguardConfig: MTU emitted/commented, PROTO default UDP - WriteConfigFile / WriteWireguardConfigFile: numeric validation rejects bad input and does not write a file - FormStep.Values(): text/password/select resolution and select default fallback Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package tui
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFormStepValues(t *testing.T) {
|
||||
f := NewFormStep("Test", []FormField{
|
||||
{
|
||||
Id: "name",
|
||||
Label: "Name",
|
||||
Default: "john",
|
||||
Type: FieldTypeText,
|
||||
},
|
||||
{
|
||||
Id: "secret",
|
||||
Label: "Secret",
|
||||
Default: "hunter2",
|
||||
Type: FieldTypePassword,
|
||||
},
|
||||
{
|
||||
Id: "proto",
|
||||
Label: "Protocol",
|
||||
Default: "TCP",
|
||||
Type: FieldTypeSelect,
|
||||
Options: []string{"UDP", "TCP"},
|
||||
},
|
||||
{
|
||||
Id: "mode",
|
||||
Label: "Mode",
|
||||
Type: FieldTypeSelect,
|
||||
Options: []string{"a", "b", "c"},
|
||||
},
|
||||
})
|
||||
|
||||
values := f.Values()
|
||||
|
||||
want := map[string]string{
|
||||
"name": "john", // text default
|
||||
"secret": "hunter2",
|
||||
"proto": "TCP", // select default resolves to the matching option
|
||||
"mode": "a", // select with no default falls back to first option
|
||||
}
|
||||
|
||||
for id, exp := range want {
|
||||
if got := values[id]; got != exp {
|
||||
t.Errorf("Values()[%q] = %q, want %q", id, got, exp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormStepValues_SelectInvalidDefaultFallsBackToFirst(t *testing.T) {
|
||||
f := NewFormStep("Test", []FormField{
|
||||
{
|
||||
Id: "proto",
|
||||
Label: "Protocol",
|
||||
Default: "NOPE", // not among options
|
||||
Type: FieldTypeSelect,
|
||||
Options: []string{"UDP", "TCP"},
|
||||
},
|
||||
})
|
||||
|
||||
if got := f.Values()["proto"]; got != "UDP" {
|
||||
t.Errorf("Values()[proto] = %q, want first option %q", got, "UDP")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user