-
Notifications
You must be signed in to change notification settings - Fork 3
/
gitlab_test.go
80 lines (70 loc) · 2.07 KB
/
gitlab_test.go
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
package main
import (
"errors"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExpiryWithDate(t *testing.T) {
date, err := addExpiry(url.Values{}, "2016-11-03")
assert.Nil(t, err)
assert.Equal(t, 1, len(date))
assert.Contains(t, date, "personal_access_token[expires_at]")
}
func TestExpiryWithEmptyDate(t *testing.T) {
date, err := addExpiry(url.Values{}, "")
assert.Nil(t, err)
assert.Empty(t, date)
}
func TestExpiryWithWrongDateAtYear(t *testing.T) {
date, err := addExpiry(url.Values{}, "201-11-01")
assert.NotNil(t, err)
assert.Equal(t, errors.New("Year is too short"), err)
assert.Empty(t, date)
}
func TestExpiryWithWrongDateAtMonth(t *testing.T) {
date, err := addExpiry(url.Values{}, "2016-1-01")
assert.NotNil(t, err)
assert.Equal(t, errors.New("Month is too short needs to be with zero digest"), err)
assert.Empty(t, date)
}
func TestExpiryWithWrongDateAtDay(t *testing.T) {
date, err := addExpiry(url.Values{}, "2016-11-1")
assert.NotNil(t, err)
assert.Equal(t, errors.New("Day is too short needs to be with zero digest"), err)
assert.Empty(t, date)
}
func TestExpiryWithWrongDateFormat(t *testing.T) {
date, err := addExpiry(url.Values{}, "2016/11/01")
assert.NotNil(t, err)
assert.Equal(t, errors.New("Date is too short it should be formatted like this 2017-12-03"), err)
assert.Empty(t, date)
}
func TestAccessToken(t *testing.T) {
request := GitLabTokenRequest{
URL: "http://localhost:10080",
Username: "root",
Password: "abcd1234",
Scope: Scope{API: true},
Date: "",
TokenName: "gogpat-test",
}
token, err := CreateToken(request)
assert.Nil(t, err)
assert.NotEmpty(t, token)
assert.Equal(t, 20, len(token))
}
func TestFullAccessToken(t *testing.T) {
request := GitLabTokenRequest{
URL: "http://localhost:10080",
Username: "root",
Password: "abcd1234",
Scope: Scope{API: true, ReadRegistry: false, ReadUser: true, Sudo: true},
Date: "",
TokenName: "gogpat-test",
}
token, err := CreateToken(request)
assert.Nil(t, err)
assert.NotEmpty(t, token)
assert.Equal(t, 20, len(token))
}