From 13ccde3ec1dbb47c8cd08fce66499d7c2bc2f40c Mon Sep 17 00:00:00 2001 From: Tanner Stirrat Date: Mon, 23 Sep 2024 11:21:19 -0600 Subject: [PATCH 1/2] Add a test, add to README, add test running --- .github/workflows/test.yaml | 20 ++++++++++++++++++++ README.md | 20 ++++++++++++++++++++ v1/client_test.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..a269afb --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,20 @@ +--- +name: "Test" +on: + push: + branches: + - "main" + pull_request: + branches: ["*"] +jobs: + pytest: + name: "Unit and Integration Tests" + runs-on: "ubuntu-latest" + steps: + - uses: "actions/checkout@v4" + - uses: "actions/setup-go@v5" + - uses: "authzed/action-spicedb@v1" + with: + version: "latest" + - name: "Run tests" + run: "go test ./..." diff --git a/README.md b/README.md index f215774..248ca93 100644 --- a/README.md +++ b/README.md @@ -144,3 +144,23 @@ func main() { } } ``` + +### Insecure Credentials +For contexts that don't require TLS, such as a development environment or integration +tests, it's possible to set up a client that does not use TLS: + +```go +import ( + "github.com/authzed/grpcutil" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + + "github.com/authzed/authzed-go/v1" +) + +client, err := authzed.NewClient( + "localhost:50051", + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpcutil.WithInsecureBearerToken("some token"), +) +``` diff --git a/v1/client_test.go b/v1/client_test.go index 400b03c..bd0cde2 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -1,10 +1,16 @@ package authzed_test import ( + "context" "log" + "testing" "github.com/authzed/grpcutil" + "github.com/stretchr/testify/require" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + v1 "github.com/authzed/authzed-go/proto/authzed/api/v1" "github.com/authzed/authzed-go/v1" ) @@ -23,3 +29,27 @@ func ExampleNewClient() { } log.Println(client) } + +func TestWriteSchemaCall(t *testing.T) { + t.Parallel() + require := require.New(t) + + // TODO: should we get a handle on the connection in order to be able to close it? + // It should only matter in testing, but it could still be a problem. + client, err := authzed.NewClient( + "localhost:50051", + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpcutil.WithInsecureBearerToken("some token"), + ) + require.NoError(err) + + schema := ` + definition document { + relation reader: user + } + definition user {} + ` + + _, err = client.SchemaServiceClient.WriteSchema(context.Background(), &v1.WriteSchemaRequest{Schema: schema}) + require.NoError(err) +} From 67edecad433f40f18d2b8d2dc5c7dc5bff4ea7fa Mon Sep 17 00:00:00 2001 From: Tanner Stirrat Date: Mon, 23 Sep 2024 11:29:35 -0600 Subject: [PATCH 2/2] Fix reference to pytest --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a269afb..54c802b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,7 @@ on: pull_request: branches: ["*"] jobs: - pytest: + tests: name: "Unit and Integration Tests" runs-on: "ubuntu-latest" steps: