1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
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)
}
})
}
}
|