package config import ( "os" "path/filepath" "testing" ) func TestSuperuserFileFillsInWhatIsUnset(t *testing.T) { path := filepath.Join(t.TempDir(), "superuser.env") if err := os.WriteFile(path, []byte("WARP_PB_SUPERUSER_EMAIL=warp@warp.local\nWARP_PB_SUPERUSER_PASSWORD=from-the-file\n"), 0o600); err != nil { t.Fatal(err) } p := PocketBase{SuperuserFile: path} if err := p.readSuperuserFile(); err != nil { t.Fatalf("readSuperuserFile: %v", err) } if p.SuperuserEmail != "warp@warp.local" || p.SuperuserPassword != "from-the-file" { t.Errorf("read %q / %q", p.SuperuserEmail, p.SuperuserPassword) } // What the environment set wins. p = PocketBase{SuperuserFile: path, SuperuserPassword: "from-the-environment"} if err := p.readSuperuserFile(); err != nil { t.Fatalf("readSuperuserFile: %v", err) } if p.SuperuserEmail != "warp@warp.local" || p.SuperuserPassword != "from-the-environment" { t.Errorf("read %q / %q", p.SuperuserEmail, p.SuperuserPassword) } // A file not written yet is no error. p = PocketBase{SuperuserFile: filepath.Join(t.TempDir(), "missing.env")} if err := p.readSuperuserFile(); err != nil || p.SuperuserEmail != "" { t.Errorf("missing file: %q, %v", p.SuperuserEmail, err) } }