Skip to content

Commit

Permalink
Merge pull request #245 from authzed/add-documentation-of-insecure-cl…
Browse files Browse the repository at this point in the history
…ient

Add a test, add to README, add test running
  • Loading branch information
tstirrat15 authored Sep 23, 2024
2 parents bf3b3aa + 67edeca commit 89e4ea5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "Test"
on:
push:
branches:
- "main"
pull_request:
branches: ["*"]
jobs:
tests:
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 ./..."
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
```
30 changes: 30 additions & 0 deletions v1/client_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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)
}

0 comments on commit 89e4ea5

Please sign in to comment.