fix
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseOptionsRequiresConfirm(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := parseOptions("postgres://x", "a@b.com", "password1", "", 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, true, "development")
|
||||
if err == nil {
|
||||
t.Fatal("expected email error")
|
||||
}
|
||||
_, err = parseOptions("postgres://x", "a@b.com", "short", "", false, true, "development")
|
||||
if err == nil || !strings.Contains(err.Error(), "8") {
|
||||
t.Fatalf("err = %v, want min length", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseOptionsPromoteOnlySkipsPassword(t *testing.T) {
|
||||
t.Parallel()
|
||||
opts, err := parseOptions("postgres://x", "Ops@Example.COM", "", "Ops", true, 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.Name != "Ops" {
|
||||
t.Fatalf("name = %q", opts.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseOptionsRejectsDemoInProduction(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := parseOptions("postgres://x", "demo@descrybe.local", "securepass", "", 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")
|
||||
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, true, "development")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if opts.Email != "demo@descrybe.local" {
|
||||
t.Fatalf("email = %q", opts.Email)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user