117 lines
2.5 KiB
Go
117 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
|
|
"src.opensuse.org/autogits/common"
|
|
"src.opensuse.org/autogits/common/gitea-generated/models"
|
|
)
|
|
|
|
func TestObsAPIHostFromWebHost(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
api string
|
|
web string
|
|
}{
|
|
{
|
|
name: "api host",
|
|
api: "https://api.suse.de",
|
|
web: "https://build.suse.de",
|
|
},
|
|
{
|
|
name: "api host",
|
|
api: "https://api.opensuse.org",
|
|
web: "https://build.opensuse.org",
|
|
},
|
|
{
|
|
name: "other host",
|
|
api: "https://someapi.suse.de",
|
|
web: "https://someapi.suse.de",
|
|
},
|
|
{
|
|
name: "short host",
|
|
api: "https://s",
|
|
web: "https://s",
|
|
},
|
|
{
|
|
name: "other schema works",
|
|
api: "s://stuffhere",
|
|
web: "s://stuffhere",
|
|
},
|
|
{
|
|
name: "other schema works",
|
|
api: "s://api.stuffhere/foo",
|
|
web: "s://build.stuffhere/foo",
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
if r := ObsWebHostFromApiHost(test.api); r != test.web {
|
|
t.Error("Expected:", test.web, "but observed", r)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPRtoObsProjectMapping(t *testing.T) {
|
|
tests := []struct {
|
|
config common.StagingConfig
|
|
name string
|
|
pr string // org/repo/prNo
|
|
|
|
expectedProject string
|
|
}{
|
|
{
|
|
name: "Regular project",
|
|
pr: "foobar/Repo/10",
|
|
expectedProject: "home:foo:foobar:Repo:PR:10",
|
|
},
|
|
{
|
|
name: "underscore repo name",
|
|
pr: "foobar/_FooBar/10",
|
|
expectedProject: "home:foo:foobar:XFooBar:PR:10",
|
|
},
|
|
{
|
|
name: "Underscore repo and project",
|
|
pr: "_some_thing/_FooBar/11",
|
|
expectedProject: "home:foo:Xsome_thing:XFooBar:PR:11",
|
|
},
|
|
{
|
|
config: common.StagingConfig{StagingProject: "staging:project:Pull_Request"},
|
|
name: "with staging set",
|
|
pr: "_some_thing/_PrjX/14",
|
|
expectedProject: "staging:project:Pull_Request:14",
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
s := strings.Split(test.pr, "/")
|
|
n, _ := strconv.ParseInt(s[2], 10, 64)
|
|
|
|
pr := models.PullRequest{
|
|
Base: &models.PRBranchInfo{
|
|
Repo: &models.Repository{
|
|
Name: s[1],
|
|
Owner: &models.User{
|
|
UserName: s[0],
|
|
},
|
|
},
|
|
},
|
|
Index: n,
|
|
}
|
|
|
|
p := GetObsProjectAssociatedWithPr(&test.config, "home:foo", &pr)
|
|
if p != test.expectedProject {
|
|
t.Error("invalid project:", p, "Expected:", test.expectedProject)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestStatusCodeResults(t *testing.T) {
|
|
}
|