diff --git a/.gitignore b/.gitignore index d18fcfc..7358171 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ cic-custodial dist .env +covprofile \ No newline at end of file diff --git a/docker-compose.test.yaml b/docker-compose.test.yaml new file mode 100644 index 0000000..21b770e --- /dev/null +++ b/docker-compose.test.yaml @@ -0,0 +1,29 @@ +version: '3.9' +services: + redis: + image: redis:6-alpine + restart: unless-stopped + command: redis-server --save 60 1 --loglevel warning + ports: + - '6379:6379' + healthcheck: + test: ["CMD-SHELL", "redis-cli ping | grep PONG"] + interval: 10s + timeout: 5s + retries: 5 + postgres: + image: postgres:14-alpine + restart: unless-stopped + user: postgres + environment: + - POSTGRES_PASSWORD=postgres + - POSTGRES_USER=postgres + - POSTGRES_DB=cic_custodial + ports: + - '5432:5432' + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 + \ No newline at end of file diff --git a/go.mod b/go.mod index c38f150..591c4fd 100644 --- a/go.mod +++ b/go.mod @@ -29,6 +29,7 @@ require ( github.com/celo-org/celo-bls-go-other v0.6.3 // indirect github.com/celo-org/celo-bls-go-windows v0.6.3 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set v1.8.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect @@ -62,11 +63,13 @@ require ( github.com/onsi/gomega v1.24.1 // indirect github.com/pelletier/go-toml v1.7.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/tsdb v0.10.0 // indirect github.com/rivo/uniseg v0.4.3 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/spf13/cast v1.3.1 // indirect + github.com/stretchr/testify v1.8.1 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect github.com/tklauser/go-sysconf v0.3.11 // indirect github.com/tklauser/numcpus v0.6.0 // indirect diff --git a/go.sum b/go.sum index 24105ea..8a7e13c 100644 --- a/go.sum +++ b/go.sum @@ -575,6 +575,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -582,7 +584,11 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= diff --git a/internal/keystore/keystore_pg_test.go b/internal/keystore/keystore_pg_test.go new file mode 100644 index 0000000..cf3d490 --- /dev/null +++ b/internal/keystore/keystore_pg_test.go @@ -0,0 +1,53 @@ +package keystore + +import ( + "context" + "testing" + + "github.com/grassrootseconomics/cic-custodial/pkg/keypair" + "github.com/grassrootseconomics/cic-custodial/pkg/logg" + "github.com/grassrootseconomics/cic-custodial/pkg/postgres" + "github.com/stretchr/testify/suite" +) + +const ( + testDsn = "postgres://postgres:postgres@localhost:5432/cic_custodial" +) + +type ItKeystoreSuite struct { + suite.Suite + Keystore Keystore +} + +func TestItKeystoreSuite(t *testing.T) { + suite.Run(t, new(ItKeystoreSuite)) +} + +func (s *ItKeystoreSuite) SetupSuite() { + pgPool, err := postgres.NewPostgresPool(postgres.PostgresPoolOpts{ + DSN: testDsn, + }) + s.Require().NoError(err) + + ks, err := NewPostgresKeytore(Opts{ + PostgresPool: pgPool, + Logg: logg.NewLogg(logg.LoggOpts{ + Debug: true, + Caller: true, + }), + }) + s.Require().NoError(err) + s.Keystore = ks +} + +func (s *ItKeystoreSuite) Test_Write_And_Load_KeyPair() { + ctx := context.Background() + keypair, err := keypair.Generate() + s.NoError(err) + + err = s.Keystore.WriteKeyPair(ctx, keypair) + s.NoError(err) + + _, err = s.Keystore.LoadPrivateKey(ctx, keypair.Public) + s.NoError(err) +}