Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test, add to README, add test running #245

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading