package cli import "testing" func TestDeployURL(t *testing.T) { cases := []struct { name string out string want string }{ { name: "vercel json picks vercel.app not api", out: `Deploying humdrumone/guilds Inspect https://vercel.com/humdrumone/guilds/GybubpArrMaKQALBaSct613mdJGq Preview https://guilds-ivafhzmbb-humdrumone.vercel.app { "deployment": { "url": "https://guilds-ivafhzmbb-humdrumone.vercel.app", "inspectorUrl": "https://vercel.com/humdrumone/guilds/GybubpArrMaKQALBaSct613mdJGq", "deploymentApiUrl": "https://api.vercel.com/v13/deployments/dpl_GybubpArrMaKQALBaSct613mdJGq" } }`, want: "https://guilds-ivafhzmbb-humdrumone.vercel.app", }, { name: "trailing quote and comma stripped", out: `{"url": "https://example.vercel.app",}`, want: "https://example.vercel.app", }, { name: "non-vercel tool returns last url", out: "Deployed to https://my-site.netlify.app", want: "https://my-site.netlify.app", }, { name: "custom domain on vercel is kept", out: ` Inspect https://vercel.com/humdrumone/guilds/abc Success! https://guilds.quest`, want: "https://guilds.quest", }, { name: "no url", out: "nothing here", want: "", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { if got := deployURL(c.out); got != c.want { t.Errorf("deployURL() = %q, want %q", got, c.want) } }) } } func TestExpand(t *testing.T) { const sha = "96017987fe1103d2c9b1" cases := []struct { name string cmd, url, com string want string }{ { name: "url substituted for promote", cmd: "vercel promote {{url}}", url: "https://x.vercel.app", com: sha, want: "vercel promote https://x.vercel.app", }, { name: "commit and short both available", cmd: "SHA={{short}} FULL={{commit}} build", com: sha, want: "SHA=96017987 FULL=" + sha + " build", }, { name: "repeated placeholder replaced everywhere", cmd: "a {{short}} b {{short}}", com: sha, want: "a 96017987 b 96017987", }, { name: "preview has no url yet, so it expands to nothing", cmd: "deploy {{url}}", com: sha, want: "deploy ", }, { name: "short commit is left whole when under 8 chars", cmd: "{{short}}", com: "abc", want: "abc", }, { name: "command without placeholders is untouched", cmd: "vercel deploy --prebuilt --yes", com: sha, want: "vercel deploy --prebuilt --yes", }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { if got := expand(c.cmd, c.url, c.com); got != c.want { t.Errorf("expand() = %q, want %q", got, c.want) } }) } }