-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathrepository_rpm_test.go
88 lines (77 loc) · 1.7 KB
/
repository_rpm_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
81
82
83
84
85
86
87
88
package models
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
func TestRepositoryRpmSuite(t *testing.T) {
m := ModelsSuite{}
r := RepositoryRpmSuite{&m}
suite.Run(t, &r)
}
func (s *RepositoryRpmSuite) TestRepositoriesRpmsValidations() {
t := s.T()
tx := s.tx
const spName = "testrepositoriesrpmsvalidations"
testRepository := Repository{
URL: "https://example.com",
LastIntrospectionTime: nil,
LastIntrospectionError: nil,
}
testRpm := Rpm{
Name: "test-package",
Arch: "x86_64",
Version: "1.3.0",
Release: "",
Epoch: 0,
Summary: "test package",
Checksum: "SHA256:934e8895f778a2e31d2a65cba048a4085537fc819a8acd40b534bf98e1e42ffd",
}
var err error
err = tx.Create(&testRepository).Error
assert.NoError(t, err)
err = tx.Create(&testRpm).Error
assert.NoError(t, err)
var testCases []struct {
given RepositoryRpm
expected string
} = []struct {
given RepositoryRpm
expected string
}{
{
given: RepositoryRpm{
RepositoryUUID: testRepository.UUID,
RpmUUID: testRpm.UUID,
},
expected: "",
},
{
given: RepositoryRpm{
RepositoryUUID: "",
RpmUUID: testRpm.UUID,
},
expected: "RepositoryUUID cannot be empty",
},
{
given: RepositoryRpm{
RepositoryUUID: testRepository.UUID,
RpmUUID: "",
},
expected: "RpmUUID cannot be empty",
},
}
tx.SavePoint(spName)
for _, item := range testCases {
err := tx.Create(&item.given).Error
if item.expected == "" {
assert.NoError(t, err)
} else {
assert.Error(t, err)
if err != nil {
assert.Equal(t, item.expected, err.Error())
}
}
tx.RollbackTo(spName)
}
}