aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/launchpad/config_test.go
blob: 275c0d242a00d37a78079ea24501995ad011f491 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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)
		})
	}
}