-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.md
67 lines (51 loc) · 1.68 KB
/
README.md
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
<!-- markdownlint-configure-file {
"MD033": false,
"MD041": false
} -->
<div align="center">
![Tests](https://github.com/theoriginalstove/testcontainers-permify/actions/workflows/test.yaml/badge.svg?event=push)
# Permify Testcontainer - [testcontainers](https://www.testcontainers.org/) implementation for [Permify](https://permify.co)
</div>
## Install
Use `go get` to install the latest version of the library.
```bash
go get -u github.com/theoriginalstove/testcontainers-permify@latest
```
## Usage
```go
import (
"context"
"testing"
"github.com/stretchr/testify/require"
permifygrpc "github.com/Permify/permify-go/grpc"
permifytest "github.com/theoriginalstove/testcontainers-permify"
)
func TestPermify(t *testing.T) {
permifyClient := setupPermify(t)
// your code here
}
func setupPermify(t *testing.T) *permify_gcpc.Client {
ctx := context.Background()
container, err := permifytest.Run(ctx)
require.NoError(t, err)
t.Cleanup(func() {
err := container.Terminate(ctx)
require.NoError(t, err)
})
container, err := Run(ctx)
require.NoError(t, err)
t.Cleanup(func() {
err = container.Terminate(ctx)
require.NoError(t, err, "failed to terminate container")
})
host, err := container.Host(ctx)
require.NoError(t, err, "failed to fetch permify host")
grpcPort, err := container.GRPCPort(ctx)
require.NoError(t, err, "failed to fetch permify grpc api port")
client, err := permify_grpc.NewClient(permify_grpc.Config{
Endpoint: fmt.Sprintf("%s:%d", host, grpcPort),
}, grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err, "failed to initialize permify grpc clinet")
return client
}
```