aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/launchpad/config_test.go
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/launchpad/config_test.go
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/launchpad/config_test.go')
-rw-r--r--bridge/launchpad/config_test.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/bridge/launchpad/config_test.go b/bridge/launchpad/config_test.go
new file mode 100644
index 00000000..275c0d24
--- /dev/null
+++ b/bridge/launchpad/config_test.go
@@ -0,0 +1,93 @@
+package launchpad
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestSplitURL(t *testing.T) {
+ type args struct {
+ url string
+ }
+ type want struct {
+ project string
+ err error
+ }
+ tests := []struct {
+ name string
+ args args
+ want want
+ }{
+ {
+ name: "default project url",
+ args: args{
+ url: "https://launchpad.net/ubuntu",
+ },
+ want: want{
+ project: "ubuntu",
+ err: nil,
+ },
+ },
+ {
+ name: "project bugs url",
+ args: args{
+ url: "https://bugs.launchpad.net/ubuntu",
+ },
+ want: want{
+ project: "ubuntu",
+ err: nil,
+ },
+ },
+ {
+ name: "bad url",
+ args: args{
+ url: "https://launchpa.net/ubuntu",
+ },
+ want: want{
+ err: ErrBadProjectURL,
+ },
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ project, err := splitURL(tt.args.url)
+ assert.Equal(t, tt.want.err, err)
+ assert.Equal(t, tt.want.project, project)
+ })
+ }
+}
+
+func TestValidateProject(t *testing.T) {
+ type args struct {
+ project string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "public project",
+ args: args{
+ project: "ubuntu",
+ },
+ want: true,
+ },
+ {
+ name: "non existing project",
+ args: args{
+ project: "cant-find-this",
+ },
+ want: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ok, _ := validateProject(tt.args.project)
+ assert.Equal(t, tt.want, ok)
+ })
+ }
+}