Update tests with changes to gitTagInfo function
Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>
This commit is contained in:
parent
46814b3759
commit
8ea1b8973a
1 changed files with 53 additions and 74 deletions
|
|
@ -412,6 +412,14 @@ func Test_NewCmdCreate(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_createRun(t *testing.T) {
|
||||
const contentCmd = `git tag --list .* --format=%\(contents\)`
|
||||
const signatureCmd = `git tag --list .* --format=%\(contents:signature\)`
|
||||
|
||||
defaultRunStubs := func(rs *run.CommandStubber) {
|
||||
rs.Register(contentCmd, 0, "")
|
||||
rs.Register(signatureCmd, 0, "")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
isTTY bool
|
||||
|
|
@ -432,9 +440,7 @@ func Test_createRun(t *testing.T) {
|
|||
BodyProvided: true,
|
||||
Target: "",
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
"url": "https://api.github.com/releases/123",
|
||||
|
|
@ -464,9 +470,7 @@ func Test_createRun(t *testing.T) {
|
|||
Target: "",
|
||||
DiscussionCategory: "General",
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
"url": "https://api.github.com/releases/123",
|
||||
|
|
@ -496,9 +500,7 @@ func Test_createRun(t *testing.T) {
|
|||
BodyProvided: true,
|
||||
Target: "main",
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
"url": "https://api.github.com/releases/123",
|
||||
|
|
@ -527,9 +529,7 @@ func Test_createRun(t *testing.T) {
|
|||
Draft: true,
|
||||
Target: "",
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
"url": "https://api.github.com/releases/123",
|
||||
|
|
@ -558,9 +558,7 @@ func Test_createRun(t *testing.T) {
|
|||
BodyProvided: true,
|
||||
GenerateNotes: false,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
"url": "https://api.github.com/releases/123",
|
||||
|
|
@ -589,9 +587,7 @@ func Test_createRun(t *testing.T) {
|
|||
BodyProvided: true,
|
||||
GenerateNotes: true,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
"url": "https://api.github.com/releases/123",
|
||||
|
|
@ -621,9 +617,7 @@ func Test_createRun(t *testing.T) {
|
|||
GenerateNotes: true,
|
||||
NotesStartTag: "v1.1.0",
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases/generate-notes"),
|
||||
httpmock.RESTPayload(200, `{
|
||||
|
|
@ -664,9 +658,7 @@ func Test_createRun(t *testing.T) {
|
|||
GenerateNotes: true,
|
||||
NotesStartTag: "v1.1.0",
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases/generate-notes"),
|
||||
httpmock.RESTPayload(200, `{
|
||||
|
|
@ -715,9 +707,7 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
Concurrency: 1,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("HEAD", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StatusStringResponse(404, ``))
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
|
|
@ -776,9 +766,7 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
Concurrency: 1,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("HEAD", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StatusStringResponse(404, ``))
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
|
|
@ -838,9 +826,7 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
Concurrency: 1,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("HEAD", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StatusStringResponse(200, ``))
|
||||
},
|
||||
|
|
@ -868,9 +854,7 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
Concurrency: 1,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("HEAD", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StatusStringResponse(404, ``))
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.StatusStringResponse(201, `{
|
||||
|
|
@ -905,9 +889,7 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
Concurrency: 1,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("HEAD", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StatusStringResponse(404, ``))
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.StatusStringResponse(201, `{
|
||||
|
|
@ -943,9 +925,7 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
Concurrency: 1,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("HEAD", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StatusStringResponse(200, ``))
|
||||
},
|
||||
|
|
@ -974,9 +954,7 @@ func Test_createRun(t *testing.T) {
|
|||
DiscussionCategory: "general",
|
||||
Concurrency: 1,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("HEAD", "repos/OWNER/REPO/releases/tags/v1.2.3"), httpmock.StatusStringResponse(404, ``))
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.RESTPayload(201, `{
|
||||
|
|
@ -1027,7 +1005,8 @@ func Test_createRun(t *testing.T) {
|
|||
NotesFromTag: true,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "some tag message")
|
||||
rs.Register(contentCmd, 0, "some tag message")
|
||||
rs.Register(signatureCmd, 0, "")
|
||||
},
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
|
|
@ -1064,7 +1043,8 @@ func Test_createRun(t *testing.T) {
|
|||
NotesFromTag: true,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "some tag message")
|
||||
rs.Register(contentCmd, 0, "some tag message")
|
||||
rs.Register(signatureCmd, 0, "")
|
||||
},
|
||||
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
|
|
@ -1099,10 +1079,8 @@ func Test_createRun(t *testing.T) {
|
|||
Assets: []*shared.AssetForUpload(nil),
|
||||
NotesFromTag: true,
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "")
|
||||
},
|
||||
wantErr: "cannot generate release notes from tag v1.2.3 as it does not exist locally",
|
||||
runStubs: defaultRunStubs,
|
||||
wantErr: "cannot generate release notes from tag v1.2.3 as it does not exist locally",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
@ -1149,6 +1127,13 @@ func Test_createRun(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_createRun_interactive(t *testing.T) {
|
||||
const contentCmd = `git tag --list .* --format=%\(contents\)`
|
||||
const signatureCmd = `git tag --list .* --format=%\(contents:signature\)`
|
||||
|
||||
defaultRunStubs := func(rs *run.CommandStubber) {
|
||||
rs.Register(contentCmd, 1, "")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
httpStubs func(*httpmock.Registry)
|
||||
|
|
@ -1185,9 +1170,7 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
return false, nil
|
||||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 1, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("GET", "repos/OWNER/REPO/tags"), httpmock.StatusStringResponse(200, `[
|
||||
{ "name": "v1.2.3" }, { "name": "v1.2.2" }, { "name": "v1.0.0" }, { "name": "v0.1.2" }
|
||||
|
|
@ -1234,9 +1217,7 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
return false, nil
|
||||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 1, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("GET", "repos/OWNER/REPO/tags"), httpmock.StatusStringResponse(200, `[
|
||||
{ "name": "v1.2.2" }, { "name": "v1.0.0" }, { "name": "v0.1.2" }
|
||||
|
|
@ -1283,9 +1264,7 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
return false, nil
|
||||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 1, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("GET", "repos/OWNER/REPO/tags"), httpmock.StatusStringResponse(200, `[
|
||||
{ "name": "v1.2.2" }, { "name": "v1.0.0" }, { "name": "v0.1.2" }
|
||||
|
|
@ -1332,9 +1311,7 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
return false, nil
|
||||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 1, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases/generate-notes"),
|
||||
httpmock.StatusStringResponse(200, `{
|
||||
|
|
@ -1381,7 +1358,7 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 1, "")
|
||||
defaultRunStubs(rs)
|
||||
rs.Register(`git describe --tags --abbrev=0 HEAD\^`, 0, "v1.2.2\n")
|
||||
rs.Register(`git .+log .+v1\.2\.2\.\.HEAD$`, 0, "commit subject\n\ncommit body\n")
|
||||
},
|
||||
|
|
@ -1427,7 +1404,8 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "hello from annotated tag")
|
||||
rs.Register(contentCmd, 0, "hello from annotated tag")
|
||||
rs.Register(signatureCmd, 0, "")
|
||||
rs.Register(`git describe --tags --abbrev=0 v1\.2\.3\^`, 1, "")
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
|
|
@ -1456,7 +1434,8 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
TagName: "v1.2.3",
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "tag exists")
|
||||
rs.Register(contentCmd, 0, "tag exists")
|
||||
rs.Register(signatureCmd, 0, "")
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.GraphQL("RepositoryFindRef"),
|
||||
|
|
@ -1489,7 +1468,8 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "tag exists")
|
||||
rs.Register(contentCmd, 0, "tag exists")
|
||||
rs.Register(signatureCmd, 0, "")
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases/generate-notes"),
|
||||
|
|
@ -1536,9 +1516,7 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
return false, nil
|
||||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 1, "")
|
||||
},
|
||||
runStubs: defaultRunStubs,
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases/generate-notes"),
|
||||
httpmock.RESTPayload(200, `{
|
||||
|
|
@ -1591,7 +1569,7 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 1, "")
|
||||
defaultRunStubs(rs)
|
||||
rs.Register(`git .+log .+v1\.1\.0\.\.HEAD$`, 0, "commit subject\n\ncommit body\n")
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
|
|
@ -1639,7 +1617,8 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
})
|
||||
},
|
||||
runStubs: func(rs *run.CommandStubber) {
|
||||
rs.Register(`git tag --list`, 0, "tag exists")
|
||||
rs.Register(contentCmd, 0, "tag exists")
|
||||
rs.Register(signatureCmd, 0, "")
|
||||
},
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(httpmock.GraphQL("RepositoryFindRef"),
|
||||
|
|
@ -1753,8 +1732,8 @@ func Test_createRun_interactive(t *testing.T) {
|
|||
|
||||
func Test_gitTagInfo(t *testing.T) {
|
||||
const tagName = "foo"
|
||||
const contentCmd = "git tag --list foo --format=%\\(contents\\)"
|
||||
const signatureCmd = "git tag --list foo --format=%\\(contents:signature\\)"
|
||||
const contentCmd = `git tag --list foo --format=%\(contents\)`
|
||||
const signatureCmd = `git tag --list foo --format=%\(contents:signature\)`
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue