aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-05-30 12:50:21 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-05-30 12:50:21 +0200
commitebebdfdf35b29b37b5a164d73bc00ca1c2b8e895 (patch)
treece460730f1055afcaa5bdfcc5472354ab672b60d /bridge/github
parentd064a7127ec612a804e08143c7098bbc60332e83 (diff)
downloadgit-bug-ebebdfdf35b29b37b5a164d73bc00ca1c2b8e895.tar.gz
add unit tests for launchpad bridge configuration
add tests for validateUsername in Github bridge panic when compile regex fail
Diffstat (limited to 'bridge/github')
-rw-r--r--bridge/github/config.go2
-rw-r--r--bridge/github/config_test.go65
2 files changed, 63 insertions, 4 deletions
diff --git a/bridge/github/config.go b/bridge/github/config.go
index c48c11f6..4a3bddfb 100644
--- a/bridge/github/config.go
+++ b/bridge/github/config.go
@@ -418,7 +418,7 @@ func splitURL(url string) (owner string, project string, err error) {
re, err := regexp.Compile(`github\.com[/:]([a-zA-Z0-9\-_]+)/([a-zA-Z0-9\-_.]+)`)
if err != nil {
- return "", "", err
+ panic("regexp compile:" + err.Error())
}
res := re.FindStringSubmatch(cleanURL)
diff --git a/bridge/github/config_test.go b/bridge/github/config_test.go
index 6c84046a..e04f327c 100644
--- a/bridge/github/config_test.go
+++ b/bridge/github/config_test.go
@@ -32,7 +32,17 @@ func TestSplitURL(t *testing.T) {
err: nil,
},
},
-
+ {
+ name: "default issues url",
+ args: args{
+ url: "https://github.com/MichaelMure/git-bug/issues",
+ },
+ want: want{
+ owner: "MichaelMure",
+ project: "git-bug",
+ err: nil,
+ },
+ },
{
name: "default url with git extension",
args: args{
@@ -87,6 +97,46 @@ func TestSplitURL(t *testing.T) {
}
}
+func TestValidateUsername(t *testing.T) {
+ type args struct {
+ username string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "existing username",
+ args: args{
+ username: "MichaelMure",
+ },
+ want: true,
+ },
+ {
+ name: "existing organisation name",
+ args: args{
+ username: "ipfs",
+ },
+ want: true,
+ },
+ {
+ name: "non existing username",
+ args: args{
+ username: "cant-find-this",
+ },
+ want: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ok, _ := validateUsername(tt.args.username)
+ assert.Equal(t, tt.want, ok)
+ })
+ }
+}
+
func TestValidateProject(t *testing.T) {
tokenPrivateScope := os.Getenv("GITHUB_TOKEN_PRIVATE")
if tokenPrivateScope == "" {
@@ -109,7 +159,7 @@ func TestValidateProject(t *testing.T) {
want bool
}{
{
- name: "public repository and token with scope 'public_repo",
+ name: "public repository and token with scope 'public_repo'",
args: args{
project: "git-bug",
owner: "MichaelMure",
@@ -118,7 +168,7 @@ func TestValidateProject(t *testing.T) {
want: true,
},
{
- name: "private repository and token with scope 'repo",
+ name: "private repository and token with scope 'repo'",
args: args{
project: "git-bug-test-github-bridge",
owner: "MichaelMure",
@@ -135,6 +185,15 @@ func TestValidateProject(t *testing.T) {
},
want: false,
},
+ {
+ name: "project not existing",
+ args: args{
+ project: "cant-find-this",
+ owner: "organisation-not-found",
+ token: tokenPublicScope,
+ },
+ want: false,
+ },
}
for _, tt := range tests {