Skip to content

Commit

Permalink
Merge pull request #2008 from josephschorr/wasm-warnings
Browse files Browse the repository at this point in the history
Add ability to get warnings from the WASM dev interface
  • Loading branch information
josephschorr authored Jul 31, 2024
2 parents d52dfd0 + fc2b576 commit 1779380
Show file tree
Hide file tree
Showing 6 changed files with 1,042 additions and 80 deletions.
13 changes: 13 additions & 0 deletions pkg/development/wasm/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"context"
"fmt"
"strings"

Expand Down Expand Up @@ -134,6 +135,18 @@ func runOperation(devContext *development.DevContext, operation *devinterface.Op
},
}, nil

case operation.SchemaWarningsParameters != nil:
warnings, err := development.GetWarnings(context.Background(), devContext)
if err != nil {
return nil, err
}

return &devinterface.OperationResult{
SchemaWarningsResult: &devinterface.SchemaWarningsResult{
Warnings: warnings,
},
}, nil

default:
return nil, fmt.Errorf("unknown operation")
}
Expand Down
53 changes: 53 additions & 0 deletions pkg/development/wasm/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,59 @@ type editCheckResult struct {
IsConditional bool
}

func TestSchemaWarningsOperation(t *testing.T) {
type testCase struct {
name string
schema string
expectedWarning *devinterface.DeveloperWarning
}

tests := []testCase{
{
"no warnings",
`definition foo {
relation bar: foo
}`,
nil,
},
{
"permission misnamed",
`definition resource {
permission view_resource = nil
}`,
&devinterface.DeveloperWarning{
Message: "Permission \"view_resource\" references parent type \"resource\" in its name; it is recommended to drop the suffix (relation-name-references-parent)",
Line: 2,
Column: 5,
SourceCode: "view_resource",
},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
response := run(t, &devinterface.DeveloperRequest{
Context: &devinterface.RequestContext{
Schema: tc.schema,
},
Operations: []*devinterface.Operation{
{
SchemaWarningsParameters: &devinterface.SchemaWarningsParameters{},
},
},
})

require.Empty(t, response.GetDeveloperErrors())

if tc.expectedWarning == nil {
require.Empty(t, response.GetOperationsResults().Results[0].SchemaWarningsResult.Warnings)
} else {
testutil.RequireProtoEqual(t, tc.expectedWarning, response.OperationsResults.Results[0].SchemaWarningsResult.Warnings[0], "mismatching warning")
}
})
}
}

func TestCheckOperation(t *testing.T) {
type testCase struct {
name string
Expand Down
Loading

0 comments on commit 1779380

Please sign in to comment.