1
1
// VulcanizeDB
2
2
// Copyright © 2019 Vulcanize
3
-
3
+ //
4
4
// This program is free software: you can redistribute it and/or modify
5
5
// it under the terms of the GNU Affero General Public License as published by
6
6
// the Free Software Foundation, either version 3 of the License, or
7
7
// (at your option) any later version.
8
-
8
+ //
9
9
// This program is distributed in the hope that it will be useful,
10
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
// GNU Affero General Public License for more details.
13
-
13
+ //
14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
- package repositories_test
17
+ package repository_test
18
18
19
19
import (
20
+ "github.com/vulcanize/vulcanizedb/libraries/shared/repository"
20
21
"strings"
21
22
22
23
"github.com/jmoiron/sqlx"
23
24
. "github.com/onsi/ginkgo"
24
25
. "github.com/onsi/gomega"
25
26
26
27
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
27
- "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
28
28
"github.com/vulcanize/vulcanizedb/pkg/fakes"
29
29
"github.com/vulcanize/vulcanizedb/test_config"
30
30
)
31
31
32
32
var _ = Describe ("address lookup" , func () {
33
33
var (
34
34
db * postgres.DB
35
- repo repositories.AddressRepository
36
35
address = fakes .FakeAddress .Hex ()
37
36
)
38
37
BeforeEach (func () {
39
38
db = test_config .NewTestDB (test_config .NewTestNode ())
40
39
test_config .CleanTestDB (db )
41
- repo = repositories.AddressRepository {}
42
40
})
43
41
44
42
AfterEach (func () {
@@ -52,7 +50,7 @@ var _ = Describe("address lookup", func() {
52
50
53
51
Describe ("GetOrCreateAddress" , func () {
54
52
It ("creates an address record" , func () {
55
- addressId , createErr := repo .GetOrCreateAddress (db , address )
53
+ addressId , createErr := repository .GetOrCreateAddress (db , address )
56
54
Expect (createErr ).NotTo (HaveOccurred ())
57
55
58
56
var actualAddress dbAddress
@@ -63,10 +61,10 @@ var _ = Describe("address lookup", func() {
63
61
})
64
62
65
63
It ("returns the existing record id if the address already exists" , func () {
66
- createId , createErr := repo .GetOrCreateAddress (db , address )
64
+ createId , createErr := repository .GetOrCreateAddress (db , address )
67
65
Expect (createErr ).NotTo (HaveOccurred ())
68
66
69
- getId , getErr := repo .GetOrCreateAddress (db , address )
67
+ getId , getErr := repository .GetOrCreateAddress (db , address )
70
68
Expect (getErr ).NotTo (HaveOccurred ())
71
69
72
70
var addressCount int
@@ -78,20 +76,20 @@ var _ = Describe("address lookup", func() {
78
76
79
77
It ("gets upper-cased addresses" , func () {
80
78
upperAddress := strings .ToUpper (address )
81
- upperAddressId , createErr := repo .GetOrCreateAddress (db , upperAddress )
79
+ upperAddressId , createErr := repository .GetOrCreateAddress (db , upperAddress )
82
80
Expect (createErr ).NotTo (HaveOccurred ())
83
81
84
- mixedCaseAddressId , getErr := repo .GetOrCreateAddress (db , address )
82
+ mixedCaseAddressId , getErr := repository .GetOrCreateAddress (db , address )
85
83
Expect (getErr ).NotTo (HaveOccurred ())
86
84
Expect (upperAddressId ).To (Equal (mixedCaseAddressId ))
87
85
})
88
86
89
87
It ("gets lower-cased addresses" , func () {
90
88
lowerAddress := strings .ToLower (address )
91
- upperAddressId , createErr := repo .GetOrCreateAddress (db , lowerAddress )
89
+ upperAddressId , createErr := repository .GetOrCreateAddress (db , lowerAddress )
92
90
Expect (createErr ).NotTo (HaveOccurred ())
93
91
94
- mixedCaseAddressId , getErr := repo .GetOrCreateAddress (db , address )
92
+ mixedCaseAddressId , getErr := repository .GetOrCreateAddress (db , address )
95
93
Expect (getErr ).NotTo (HaveOccurred ())
96
94
Expect (upperAddressId ).To (Equal (mixedCaseAddressId ))
97
95
})
@@ -112,7 +110,7 @@ var _ = Describe("address lookup", func() {
112
110
})
113
111
114
112
It ("creates an address record" , func () {
115
- addressId , createErr := repo .GetOrCreateAddressInTransaction (tx , address )
113
+ addressId , createErr := repository .GetOrCreateAddressInTransaction (tx , address )
116
114
Expect (createErr ).NotTo (HaveOccurred ())
117
115
commitErr := tx .Commit ()
118
116
Expect (commitErr ).NotTo (HaveOccurred ())
@@ -125,10 +123,10 @@ var _ = Describe("address lookup", func() {
125
123
})
126
124
127
125
It ("returns the existing record id if the address already exists" , func () {
128
- _ , createErr := repo .GetOrCreateAddressInTransaction (tx , address )
126
+ _ , createErr := repository .GetOrCreateAddressInTransaction (tx , address )
129
127
Expect (createErr ).NotTo (HaveOccurred ())
130
128
131
- _ , getErr := repo .GetOrCreateAddressInTransaction (tx , address )
129
+ _ , getErr := repository .GetOrCreateAddressInTransaction (tx , address )
132
130
Expect (getErr ).NotTo (HaveOccurred ())
133
131
tx .Commit ()
134
132
@@ -139,10 +137,10 @@ var _ = Describe("address lookup", func() {
139
137
140
138
It ("gets upper-cased addresses" , func () {
141
139
upperAddress := strings .ToUpper (address )
142
- upperAddressId , createErr := repo .GetOrCreateAddressInTransaction (tx , upperAddress )
140
+ upperAddressId , createErr := repository .GetOrCreateAddressInTransaction (tx , upperAddress )
143
141
Expect (createErr ).NotTo (HaveOccurred ())
144
142
145
- mixedCaseAddressId , getErr := repo .GetOrCreateAddressInTransaction (tx , address )
143
+ mixedCaseAddressId , getErr := repository .GetOrCreateAddressInTransaction (tx , address )
146
144
Expect (getErr ).NotTo (HaveOccurred ())
147
145
tx .Commit ()
148
146
@@ -151,10 +149,10 @@ var _ = Describe("address lookup", func() {
151
149
152
150
It ("gets lower-cased addresses" , func () {
153
151
lowerAddress := strings .ToLower (address )
154
- upperAddressId , createErr := repo .GetOrCreateAddressInTransaction (tx , lowerAddress )
152
+ upperAddressId , createErr := repository .GetOrCreateAddressInTransaction (tx , lowerAddress )
155
153
Expect (createErr ).NotTo (HaveOccurred ())
156
154
157
- mixedCaseAddressId , getErr := repo .GetOrCreateAddressInTransaction (tx , address )
155
+ mixedCaseAddressId , getErr := repository .GetOrCreateAddressInTransaction (tx , address )
158
156
Expect (getErr ).NotTo (HaveOccurred ())
159
157
tx .Commit ()
160
158
@@ -164,16 +162,16 @@ var _ = Describe("address lookup", func() {
164
162
165
163
Describe ("GetAddressById" , func () {
166
164
It ("gets and address by it's id" , func () {
167
- addressId , createErr := repo .GetOrCreateAddress (db , address )
165
+ addressId , createErr := repository .GetOrCreateAddress (db , address )
168
166
Expect (createErr ).NotTo (HaveOccurred ())
169
167
170
- actualAddress , getErr := repo .GetAddressById (db , addressId )
168
+ actualAddress , getErr := repository .GetAddressById (db , addressId )
171
169
Expect (getErr ).NotTo (HaveOccurred ())
172
170
Expect (actualAddress ).To (Equal (address ))
173
171
})
174
172
175
173
It ("returns an error if the id doesn't exist" , func () {
176
- _ , getErr := repo .GetAddressById (db , 0 )
174
+ _ , getErr := repository .GetAddressById (db , 0 )
177
175
Expect (getErr ).To (HaveOccurred ())
178
176
Expect (getErr ).To (MatchError ("sql: no rows in result set" ))
179
177
})
0 commit comments