Skip to content

Commit

Permalink
improve unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Feb 24, 2024
1 parent 27158e8 commit 143fc68
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion codegen/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func generateConnector(rawSchema *RawConnectorSchema, srcPath string, moduleName

importLines := []string{}
for importPath := range rawSchema.Imports {
importLines = append(importLines, importPath)
importLines = append(importLines, fmt.Sprintf(`"%s"`, importPath))
}
targetPath := path.Join(srcPath, connectorOutputFile)
f, err := os.Create(targetPath)
Expand Down
3 changes: 0 additions & 3 deletions codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ func (sp *SchemaParser) parseOperationInfo(functionName string, pos token.Pos) *
log.Debug().Msgf("unsupported operation kind: %s", matches)
}

log.Printf("matches: %v", matches)
if matchesLen > 3 && strings.TrimSpace(matches[3]) != "" {
result.Name = strings.TrimSpace(matches[3])
} else {
Expand Down Expand Up @@ -523,9 +522,7 @@ func findCommentsFromPos(fset *token.FileSet, files map[string]*ast.File, pos to
continue
}
offset := pos - 10
// log.Printf("file: %s, pos: %v, position: %v", fName, pos, position.Filename)
for _, cg := range f.Comments {
// log.Printf("text: %s, end: %v, pos: %v - %v", cg.Text(), cg.End(), offset, pos)
if len(cg.List) > 0 && (cg.Pos() <= token.Pos(offset) && cg.End() >= token.Pos(offset)) {
return cg
}
Expand Down
3 changes: 1 addition & 2 deletions codegen/templates/new/connector.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/hasura/ndc-sdk-go/connector"
"github.com/hasura/ndc-sdk-go/schema"
"github.com/swaggest/jsonschema-go"
"{{.Module}}/types"
)

Expand All @@ -14,7 +13,7 @@ type Connector struct{}

// ParseConfiguration validates the configuration files provided by the user, returning a validated 'Configuration',
// or throwing an error to prevents Connector startup.
func ParseConfiguration(configurationDir string) (*types.Configuration, error) {
func (connector *Connector) ParseConfiguration(configurationDir string) (*types.Configuration, error) {
return &types.Configuration{}, nil
}

Expand Down
3 changes: 1 addition & 2 deletions codegen/templates/new/go.mod.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ module {{.Module}}
go 1.18

require (
github.com/hasura/ndc-sdk-go v0.0.0-20240218161048-ce1f9dfc50bc
github.com/swaggest/jsonschema-go v0.3.64
github.com/hasura/ndc-sdk-go v0.0.0-20240223161935-98c2e9f3b445
)
2 changes: 1 addition & 1 deletion codegen/templates/new/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func main() {
if err := connector.Start[types.RawConfiguration, types.Configuration, types.State](
if err := connector.Start[types.Configuration, types.State](
&Connector{},
connector.WithMetricsPrefix("{{.Name}}"),
connector.WithDefaultServiceName("{{.Name}}"),
Expand Down
10 changes: 8 additions & 2 deletions codegen/testdata/basic/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"CreateArticleArgumentsAuthor": {
"fields": {
"created_at": { "type": { "name": "DateTime", "type": "named" } },
"id": { "type": { "name": "String", "type": "named" } }
"id": { "type": { "name": "UUID", "type": "named" } }
}
},
"CreateArticleResult": {
Expand Down Expand Up @@ -137,7 +137,13 @@
}
},
"name": "create_article",
"result_type": { "name": "CreateArticleResult", "type": "named" }
"result_type": {
"type": "nullable",
"underlying_type": {
"name": "CreateArticleResult",
"type": "named"
}
}
},
{
"arguments": {
Expand Down
12 changes: 5 additions & 7 deletions codegen/testdata/basic/source/comment.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func GetArticles(ctx context.Context, state *State, arguments *GetArticlesArgume

type CreateArticleArguments struct {
Author struct {
ID string `json:"id"`
ID uuid.UUID `json:"id"`
CreatedAt time.Time `json:"created_at"`
} `json:"author"`
}
Expand All @@ -45,11 +45,9 @@ type CreateArticleResult struct {
}

// @procedure create_article
func CreateArticle(ctx context.Context, state *State, arguments *CreateArticleArguments) (CreateArticleResult, error) {
return []CreateArticleResult{
{
ID: 1,
Authors: []Author{},
},
func CreateArticle(ctx context.Context, state *State, arguments *CreateArticleArguments) (*CreateArticleResult, error) {
return &CreateArticleResult{
ID: 1,
Authors: []Author{},
}, nil
}

0 comments on commit 143fc68

Please sign in to comment.