Skip to content

Commit a296501

Browse files
committed
poc: working base test for showing how to create a pgtestdb connection that supports pgxpool injection
1 parent 889db41 commit a296501

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Diff for: packages/go/bhlog/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
module github.com/specterops/bloodhound/bhlog
1818

1919
go 1.23
20+
21+
require github.com/peterldowns/pgtestdb v0.1.1

Diff for: packages/go/bhlog/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/peterldowns/pgtestdb v0.1.1 h1:+hBCD1DcbKeg5Sfg0G+5WNIy/Cm0ORgwMkF4ygihrmU=
2+
github.com/peterldowns/pgtestdb v0.1.1/go.mod h1:yVWInWV0dxvmLdL2ao3nXDzWZ9+G6EhJ4gRwvI1Ozeg=

Diff for: packages/go/bhlog/random_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package bhlog_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
_ "github.com/jackc/pgx/v5"
8+
_ "github.com/jackc/pgx/v5/stdlib"
9+
"github.com/peterldowns/pgtestdb"
10+
"github.com/specterops/bloodhound/dawgs"
11+
"github.com/specterops/bloodhound/dawgs/drivers/pg"
12+
"github.com/specterops/bloodhound/graphschema"
13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
15+
)
16+
17+
func TestRandom(t *testing.T) {
18+
var ctx = context.Background()
19+
20+
conf := pgtestdb.Config{
21+
DriverName: "pgx",
22+
User: "bhe",
23+
Password: "weneedbetterpasswords",
24+
Host: "localhost",
25+
Port: "55432",
26+
Options: "sslmode=disable",
27+
}
28+
29+
connConf := pgtestdb.Custom(t, conf, pgtestdb.NoopMigrator{})
30+
31+
pool, err := pg.NewPool(connConf.URL())
32+
require.Nil(t, err)
33+
34+
graphDB, err := dawgs.Open(ctx, pg.DriverName, dawgs.Config{
35+
GraphQueryMemoryLimit: 1024 * 1024 * 1024 * 2,
36+
ConnectionString: connConf.URL(),
37+
Pool: pool,
38+
})
39+
require.Nil(t, err)
40+
41+
err = graphDB.AssertSchema(ctx, graphschema.DefaultGraphSchema())
42+
assert.Nil(t, err)
43+
}

0 commit comments

Comments
 (0)