-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathrepository_test.go
77 lines (64 loc) · 1.52 KB
/
repository_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
package models
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type RepositorySuite struct {
*ModelsSuite
}
func TestRepositorySuite(t *testing.T) {
m := ModelsSuite{}
r := RepositorySuite{&m}
suite.Run(t, &r)
}
func (s *RepositorySuite) TestRepositoriesCreate() {
var now = time.Now()
var repo = Repository{
URL: "https://example.com",
LastIntrospectionTime: &now,
LastIntrospectionError: nil,
}
var found = Repository{}
tx := s.tx
tx.Create(&repo)
assert.Nil(s.T(), tx.Error)
err := tx.Where("url = ?", repo.URL).First(&found).Error
assert.Nil(s.T(), err)
assert.NotEmpty(s.T(), found.UUID)
assert.True(s.T(), strings.HasSuffix(found.URL, "/")) // test trailing slash added during creation
}
func (s *ModelsSuite) TestCleanupURL() {
tx := s.tx
var found Repository
type TestCase struct {
given string
expected string
}
testCases := []TestCase{
{
given: "https://one.example.com",
expected: "https://one.example.com/",
},
{
given: " https://two.example.com ",
expected: "https://two.example.com/",
},
{
given: "https://three.example.com/path/////",
expected: "https://three.example.com/path/",
},
}
for i := 0; i < len(testCases); i++ {
repo := Repository{
URL: testCases[i].given,
}
tx.Create(&repo)
assert.Nil(s.T(), tx.Error)
err := tx.Where("url = ?", testCases[i].expected).Find(&found).Error
assert.Nil(s.T(), err)
assert.NotEmpty(s.T(), found.UUID)
}
}