Skip to content

Commit d510ff3

Browse files
committed
Move tests back to _test package, simplify stubs
Signed-off-by: Matthew Sykes <[email protected]>
1 parent c54a7c7 commit d510ff3

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

lib/server/db/mysql/mysql_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ Copyright IBM Corp. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package mysql
7+
package mysql_test
88

99
import (
1010
"context"
1111
"errors"
1212
"path/filepath"
1313

14+
"github.com/hyperledger/fabric-ca/lib/server/db/mysql"
1415
"github.com/hyperledger/fabric-ca/lib/server/db/mysql/mocks"
1516
"github.com/hyperledger/fabric-ca/lib/tls"
1617
. "github.com/onsi/ginkgo"
@@ -23,7 +24,7 @@ const (
2324

2425
var _ = Describe("Mysql", func() {
2526
var (
26-
db *Mysql
27+
db *mysql.Mysql
2728
mockDB *mocks.FabricCADB
2829
)
2930

@@ -32,7 +33,7 @@ var _ = Describe("Mysql", func() {
3233
Enabled: true,
3334
CertFiles: []string{filepath.Join(testdataDir, "root.pem")},
3435
}
35-
db = NewDB(
36+
db = mysql.NewDB(
3637
"root:rootpw@tcp(localhost:3306)/fabric_ca_db",
3738
"",
3839
tls,
@@ -103,12 +104,10 @@ var _ = Describe("Mysql", func() {
103104

104105
When("the database already exists", func() {
105106
It("does not attempt to create the database", func() {
106-
mockDB.GetCalls(func(s string, i interface{}, s2 string, i2 ...interface{}) error {
107-
exists := i.(*bool)
108-
*exists = true
109-
i = exists
107+
mockDB.GetStub = func(s string, i interface{}, s2 string, i2 ...interface{}) error {
108+
*(i.(*bool)) = true
110109
return nil
111-
})
110+
}
112111
db.SqlxDB = mockDB
113112
sqlxDB, err := db.CreateDatabase()
114113
Expect(err).NotTo(HaveOccurred())

lib/server/db/postgres/postgres_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ Copyright IBM Corp. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package postgres
7+
package postgres_test
88

99
import (
1010
"context"
1111
"path/filepath"
1212

13+
"github.com/hyperledger/fabric-ca/lib/server/db/postgres"
1314
"github.com/hyperledger/fabric-ca/lib/server/db/postgres/mocks"
1415
"github.com/hyperledger/fabric-ca/lib/tls"
1516
. "github.com/onsi/ginkgo"
@@ -23,7 +24,7 @@ const (
2324

2425
var _ = Describe("Postgres", func() {
2526
var (
26-
db *Postgres
27+
db *postgres.Postgres
2728
mockDB *mocks.FabricCADB
2829
)
2930

@@ -32,7 +33,7 @@ var _ = Describe("Postgres", func() {
3233
Enabled: true,
3334
CertFiles: []string{filepath.Join(testdataDir, "root.pem")},
3435
}
35-
db = NewDB(
36+
db = postgres.NewDB(
3637
"host=localhost port=5432 user=root password=rootpw dbname=fabric_ca",
3738
"",
3839
tls,
@@ -43,7 +44,7 @@ var _ = Describe("Postgres", func() {
4344

4445
Context("open connection to database", func() {
4546
It("fails to connect if the contains incorrect syntax", func() {
46-
db = NewDB(
47+
db = postgres.NewDB(
4748
"hos) (t=localhost port=5432 user=root password=rootpw dbname=fabric-ca",
4849
"",
4950
nil,
@@ -53,7 +54,7 @@ var _ = Describe("Postgres", func() {
5354
Expect(err).To(HaveOccurred())
5455
Expect(err.Error()).Should(Equal("Database name 'fabric-ca' cannot contain any '-' or end with '.db'"))
5556

56-
db = NewDB(
57+
db = postgres.NewDB(
5758
"host=localhost port=5432 user=root password=rootpw dbname=fabric_ca.db",
5859
"",
5960
nil,
@@ -148,12 +149,10 @@ var _ = Describe("Postgres", func() {
148149

149150
When("the database already exists", func() {
150151
It("does not attempt to create the database", func() {
151-
mockDB.GetCalls(func(s string, i interface{}, s2 string, i2 ...interface{}) error {
152-
exists := i.(*bool)
153-
*exists = true
154-
i = exists
152+
mockDB.GetStub = func(s string, i interface{}, s2 string, i2 ...interface{}) error {
153+
*(i.(*bool)) = true
155154
return nil
156-
})
155+
}
157156
db.SqlxDB = mockDB
158157
sqlxDB, err := db.CreateDatabase()
159158
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)