Files
2026-08-13 23:40:39 +02:00

93 lines
2.9 KiB
Go

package main
import (
"strings"
"testing"
)
func TestParseOptionsRequiresPostgres(t *testing.T) {
t.Parallel()
_, 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)
}
}
func TestParseOptionsRequiresConfirm(t *testing.T) {
t.Parallel()
_, 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)
}
}
func TestParseOptionsRequiresEmailAndPassword(t *testing.T) {
t.Parallel()
_, 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, 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", "Acme", true, false, true, "production")
if err != nil {
t.Fatal(err)
}
if opts.Email != "ops@example.com" {
t.Fatalf("email = %q", opts.Email)
}
if opts.Password != "" || !opts.PromoteOnly {
t.Fatalf("promote-only opts = %+v", opts)
}
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, 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, false, true, "prod")
if err == nil || !strings.Contains(err.Error(), "seed-demo password") {
t.Fatalf("err = %v, want demo password refuse", err)
}
}
func TestParseOptionsAllowsDemoLocally(t *testing.T) {
t.Parallel()
opts, err := parseOptions("postgres://x", "demo@descrybe.local", "DemoPass123!", "", "", false, false, true, "development")
if err != nil {
t.Fatal(err)
}
if opts.Email != "demo@descrybe.local" {
t.Fatalf("email = %q", opts.Email)
}
}