This commit is contained in:
2026-08-13 23:40:39 +02:00
parent 260fe28ac0
commit 322c70e5cf
4 changed files with 160 additions and 39 deletions
+28 -10
View File
@@ -7,7 +7,7 @@ import (
func TestParseOptionsRequiresPostgres(t *testing.T) {
t.Parallel()
_, err := parseOptions("", "a@b.com", "password1", "", false, true, "development")
_, err := parseOptions("", "a@b.com", "password1", "", "", false, false, true, "development")
if err == nil || !strings.Contains(err.Error(), "DATABASE_URL") {
t.Fatalf("err = %v, want DATABASE_URL required", err)
}
@@ -15,7 +15,7 @@ func TestParseOptionsRequiresPostgres(t *testing.T) {
func TestParseOptionsRequiresConfirm(t *testing.T) {
t.Parallel()
_, err := parseOptions("postgres://x", "a@b.com", "password1", "", false, false, "development")
_, err := parseOptions("postgres://x", "a@b.com", "password1", "", "", false, false, false, "development")
if err == nil || !strings.Contains(err.Error(), "-confirm") {
t.Fatalf("err = %v, want -confirm required", err)
}
@@ -23,19 +23,37 @@ func TestParseOptionsRequiresConfirm(t *testing.T) {
func TestParseOptionsRequiresEmailAndPassword(t *testing.T) {
t.Parallel()
_, err := parseOptions("postgres://x", "", "password1", "", false, true, "development")
_, err := parseOptions("postgres://x", "", "password1", "", "", false, false, true, "development")
if err == nil {
t.Fatal("expected email error")
}
_, err = parseOptions("postgres://x", "a@b.com", "short", "", false, true, "development")
_, err = parseOptions("postgres://x", "a@b.com", "short", "", "", false, false, true, "development")
if err == nil || !strings.Contains(err.Error(), "8") {
t.Fatalf("err = %v, want min length", err)
}
}
func TestParseOptionsDefaultCompanyName(t *testing.T) {
t.Parallel()
opts, err := parseOptions("postgres://x", "ops@example.com", "password1", "Ops", "", false, false, true, "development")
if err != nil {
t.Fatal(err)
}
if opts.CompanyName != "Ops workspace" {
t.Fatalf("company = %q", opts.CompanyName)
}
opts, err = parseOptions("postgres://x", "ops@example.com", "password1", "Ops", "Acme", false, false, true, "development")
if err != nil {
t.Fatal(err)
}
if opts.CompanyName != "Acme" {
t.Fatalf("company = %q", opts.CompanyName)
}
}
func TestParseOptionsPromoteOnlySkipsPassword(t *testing.T) {
t.Parallel()
opts, err := parseOptions("postgres://x", "Ops@Example.COM", "", "Ops", true, true, "production")
opts, err := parseOptions("postgres://x", "Ops@Example.COM", "", "Ops", "Acme", true, false, true, "production")
if err != nil {
t.Fatal(err)
}
@@ -45,18 +63,18 @@ func TestParseOptionsPromoteOnlySkipsPassword(t *testing.T) {
if opts.Password != "" || !opts.PromoteOnly {
t.Fatalf("promote-only opts = %+v", opts)
}
if opts.Name != "Ops" {
t.Fatalf("name = %q", opts.Name)
if opts.CompanyName != "Acme" {
t.Fatalf("company = %q", opts.CompanyName)
}
}
func TestParseOptionsRejectsDemoInProduction(t *testing.T) {
t.Parallel()
_, err := parseOptions("postgres://x", "demo@descrybe.local", "securepass", "", false, true, "production")
_, err := parseOptions("postgres://x", "demo@descrybe.local", "securepass", "", "", false, false, true, "production")
if err == nil || !strings.Contains(err.Error(), "demo/local") {
t.Fatalf("err = %v, want demo/local refuse", err)
}
_, err = parseOptions("postgres://x", "you@example.com", "DemoPass123!", "", false, true, "prod")
_, err = parseOptions("postgres://x", "you@example.com", "DemoPass123!", "", "", false, false, true, "prod")
if err == nil || !strings.Contains(err.Error(), "seed-demo password") {
t.Fatalf("err = %v, want demo password refuse", err)
}
@@ -64,7 +82,7 @@ func TestParseOptionsRejectsDemoInProduction(t *testing.T) {
func TestParseOptionsAllowsDemoLocally(t *testing.T) {
t.Parallel()
opts, err := parseOptions("postgres://x", "demo@descrybe.local", "DemoPass123!", "", false, true, "development")
opts, err := parseOptions("postgres://x", "demo@descrybe.local", "DemoPass123!", "", "", false, false, true, "development")
if err != nil {
t.Fatal(err)
}