Skip to content

Commit

Permalink
Remove single check method and rename CheckMany to Check
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyphu committed Jul 15, 2024
1 parent e6c6710 commit b6d196a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
21 changes: 1 addition & 20 deletions pkg/fga/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,6 @@ type WarrantCheck struct {
}

type CheckOpts struct {
// Warrant to check
Warrant WarrantCheck `json:"warrant_check"`

// Flag to include debug information in the response.
Debug bool `json:"debug,omitempty"`

// Optional token to specify desired read consistency
WarrantToken string `json:"-"`
}

type CheckManyOpts struct {
// The operator to use for the given warrants.
Op string `json:"op,omitempty"`

Expand Down Expand Up @@ -783,14 +772,6 @@ func (c *Client) BatchWriteWarrants(ctx context.Context, opts []WriteWarrantOpts
}

func (c *Client) Check(ctx context.Context, opts CheckOpts) (CheckResponse, error) {
return c.CheckMany(ctx, CheckManyOpts{
Checks: []WarrantCheck{opts.Warrant},
Debug: opts.Debug,
WarrantToken: opts.WarrantToken,
})
}

func (c *Client) CheckMany(ctx context.Context, opts CheckManyOpts) (CheckResponse, error) {
c.once.Do(c.init)

data, err := c.JSONEncode(opts)
Expand Down Expand Up @@ -835,7 +816,7 @@ func (c *Client) CheckMany(ctx context.Context, opts CheckManyOpts) (CheckRespon
func (c *Client) CheckBatch(ctx context.Context, opts CheckBatchOpts) ([]CheckResponse, error) {
c.once.Do(c.init)

checkOpts := CheckManyOpts{
checkOpts := CheckOpts{
Op: "batch",
Checks: opts.Warrants,
Debug: opts.Debug,
Expand Down
12 changes: 6 additions & 6 deletions pkg/fga/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,11 +1012,11 @@ func writeWarrantTestHandler(w http.ResponseWriter, r *http.Request) {
w.Write(body)
}

func TestCheckMany(t *testing.T) {
func TestCheck(t *testing.T) {
tests := []struct {
scenario string
client *Client
options CheckManyOpts
options CheckOpts
expected CheckResponse
err bool
}{
Expand All @@ -1030,7 +1030,7 @@ func TestCheckMany(t *testing.T) {
client: &Client{
APIKey: "test",
},
options: CheckManyOpts{
options: CheckOpts{
Checks: []WarrantCheck{
{
ObjectType: "report",
Expand All @@ -1053,14 +1053,14 @@ func TestCheckMany(t *testing.T) {

for _, test := range tests {
t.Run(test.scenario, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(checkManyTestHandler))
server := httptest.NewServer(http.HandlerFunc(checkTestHandler))
defer server.Close()

client := test.client
client.Endpoint = server.URL
client.HTTPClient = server.Client()

checkResult, err := client.CheckMany(context.Background(), test.options)
checkResult, err := client.Check(context.Background(), test.options)
if test.err {
require.Error(t, err)
return
Expand All @@ -1071,7 +1071,7 @@ func TestCheckMany(t *testing.T) {
}
}

func checkManyTestHandler(w http.ResponseWriter, r *http.Request) {
func checkTestHandler(w http.ResponseWriter, r *http.Request) {
auth := r.Header.Get("Authorization")
if auth != "Bearer test" {
http.Error(w, "bad auth", http.StatusUnauthorized)
Expand Down

0 comments on commit b6d196a

Please sign in to comment.