workflow-pr: tests
This commit is contained in:
parent
2bc9830a7a
commit
2916ec8da5
26
workflow-pr/maintainership.go
Normal file
26
workflow-pr/maintainership.go
Normal file
@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import "src.opensuse.org/autogits/common"
|
||||
|
||||
//go:generate mockgen -source=maintainership.go -destination=mock/maintainership.go -typed
|
||||
|
||||
type GiteaMaintainershipInterface interface {
|
||||
FetchMaintainershipFile(org, prj, branch string) ([]byte, error)
|
||||
}
|
||||
|
||||
func MaintainerListForProject(gitea GiteaMaintainershipInterface, org, branch string) ([]string, error) {
|
||||
_, err := gitea.FetchMaintainershipFile(org, common.DefaultGitPrj, branch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func MaintainerListForPackage(gitea GiteaMaintainershipInterface, org, pkg, branch string) ([]string, error) {
|
||||
_, err := gitea.FetchMaintainershipFile(org, pkg, branch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []string{}, nil
|
||||
}
|
89
workflow-pr/maintainership_test.go
Normal file
89
workflow-pr/maintainership_test.go
Normal file
@ -0,0 +1,89 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"go.uber.org/mock/gomock"
|
||||
"src.opensuse.org/autogits/common"
|
||||
mock_main "src.opensuse.org/workflow-pr/mock"
|
||||
)
|
||||
|
||||
func TestMaintainership(t *testing.T) {
|
||||
MaintainershipFile := []byte(`
|
||||
{
|
||||
"*": ["user1", "user2"]
|
||||
}
|
||||
`)
|
||||
|
||||
t.Run("No maintainer in empty package", func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mi := mock_main.NewMockGiteaMaintainershipInterface(ctl)
|
||||
|
||||
mi.EXPECT().FetchMaintainershipFile("foo", "goo", "bar").Return(nil, nil)
|
||||
|
||||
m, err := MaintainerListForPackage(mi, "foo", "goo", "bar")
|
||||
if len(m) != 0 || err != nil {
|
||||
t.Error("Invalid number of maintainers for package", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("No maintainer for empty projects", func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mi := mock_main.NewMockGiteaMaintainershipInterface(ctl)
|
||||
|
||||
mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, nil)
|
||||
|
||||
m, err := MaintainerListForProject(mi, "foo", "bar")
|
||||
if len(m) != 0 || err != nil {
|
||||
t.Error("Invalid number of maintainers for project", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Error in MaintainerListForPackage when remote has an error", func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mi := mock_main.NewMockGiteaMaintainershipInterface(ctl)
|
||||
|
||||
err := errors.New("some error here")
|
||||
mi.EXPECT().FetchMaintainershipFile("foo", "goo", "bar").Return(nil, err)
|
||||
|
||||
_, errRet := MaintainerListForPackage(mi, "foo", "goo", "bar")
|
||||
switch errRet {
|
||||
case nil:
|
||||
t.Error("Should have returned an error")
|
||||
case err:
|
||||
break
|
||||
default:
|
||||
t.Error("Unexpected error received", err)
|
||||
}
|
||||
})
|
||||
t.Run("Error in MaintainerListForProject when remote has an error", func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mi := mock_main.NewMockGiteaMaintainershipInterface(ctl)
|
||||
|
||||
err := errors.New("some error here")
|
||||
mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(nil, err)
|
||||
|
||||
_, errRet := MaintainerListForProject(mi, "foo", "bar")
|
||||
switch errRet {
|
||||
case nil:
|
||||
t.Error("Should have returned an error")
|
||||
case err:
|
||||
break
|
||||
default:
|
||||
t.Error("Unexpected error received", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Project maintainers", func(t *testing.T) {
|
||||
ctl := gomock.NewController(t)
|
||||
mi := mock_main.NewMockGiteaMaintainershipInterface(ctl)
|
||||
|
||||
mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(MaintainershipFile, nil)
|
||||
|
||||
m, err := MaintainerListForProject(mi, "foo", "bar")
|
||||
if len(m) != 2 || err != nil {
|
||||
t.Error("Invalid number of maintainers for project", err)
|
||||
}
|
||||
})
|
||||
}
|
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"go.uber.org/mock/gomock"
|
||||
|
Loading…
Reference in New Issue
Block a user