-
Notifications
You must be signed in to change notification settings - Fork 38
/
integrationtest_suite_test.go
79 lines (64 loc) · 1.57 KB
/
integrationtest_suite_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
package integrationtest_test
import (
"os"
"path/filepath"
"testing"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
"github.com/pborman/uuid"
)
func TestIntegration(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Integration Test Suite")
}
var (
csb string
fixtures func(string) string
database string
dbConn *gorm.DB
)
var _ = SynchronizedBeforeSuite(
func() []byte {
// -gcflags enabled "gops", but had to be removed as this doesn't compile with Go 1.19
//path, err := Build("github.com/cloudfoundry/cloud-service-broker", `-gcflags="all=-N -l"`)
path, err := Build("github.com/cloudfoundry/cloud-service-broker")
Expect(err).NotTo(HaveOccurred())
return []byte(path)
},
func(data []byte) {
csb = string(data)
cwd, err := os.Getwd()
Expect(err).NotTo(HaveOccurred())
fixtures = func(name string) string {
return filepath.Join(cwd, "fixtures", name)
}
},
)
var _ = SynchronizedAfterSuite(
func() {},
func() { CleanupBuildArtifacts() },
)
var _ = BeforeEach(func() {
fh, err := os.CreateTemp(os.TempDir(), "csbdb")
Expect(err).NotTo(HaveOccurred())
defer fh.Close()
database = fh.Name()
DeferCleanup(func() {
cleanup(database)
})
dbConn, err = gorm.Open(sqlite.Open(database), &gorm.Config{})
Expect(err).NotTo(HaveOccurred())
})
func requestID() string {
return uuid.New()
}
func must[A any](a A, err error) A {
Expect(err).WithOffset(1).NotTo(HaveOccurred())
return a
}
func cleanup(path string) {
Expect(os.RemoveAll(path)).To(Succeed())
}