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

chore: fix missing references in toOpts and changes with newlines #3240

Merged
merged 13 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 4 additions & 4 deletions pkg/sdk/poc/example/to_opts_optional_example_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
//go:generate go run ../main.go

var ToOptsOptionalExample = g.NewInterface(
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved
"ToOptsOptionalExamples",
"ToOptsOptionalExample",
"FeaturesExample",
"FeaturesExamples",
g.KindOfT[DatabaseObjectIdentifier](),
).AlterOperation("https://example.com",
g.NewQueryStruct("Alter").
Expand All @@ -24,7 +24,7 @@ var ToOptsOptionalExample = g.NewInterface(
QueryStructField(
"RequiredField",
g.NewQueryStruct("RequiredField").
List("SomeRequiredList", "DatabaseObjectIdentifier", g.ListOptions()),
g.KeywordOptions(),
List("SomeRequiredList", "DatabaseObjectIdentifier", g.ListOptions().Required()),
g.KeywordOptions().Required(),
),
)
8 changes: 4 additions & 4 deletions pkg/sdk/poc/example/to_opts_optional_example_dto_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package example

//go:generate go run ./dto-builder-generator/main.go

var _ optionsProvider[AlterToOptsOptionalExampleOptions] = new(AlterToOptsOptionalExampleRequest)
var _ optionsProvider[AlterFeaturesExamplesOptions] = new(AlterFeaturesExamplesRequest)

type AlterToOptsOptionalExampleRequest struct {
type AlterFeaturesExamplesRequest struct {
IfExists *bool
name DatabaseObjectIdentifier // required
OptionalField *OptionalFieldRequest
RequiredField RequiredFieldRequest
RequiredField RequiredFieldRequest // required
}

type OptionalFieldRequest struct {
SomeList []DatabaseObjectIdentifier
}

type RequiredFieldRequest struct {
SomeRequiredList []DatabaseObjectIdentifier
SomeRequiredList []DatabaseObjectIdentifier // required
}
10 changes: 6 additions & 4 deletions pkg/sdk/poc/example/to_opts_optional_example_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ package example

import "context"

type ToOptsOptionalExamples interface {
Alter(ctx context.Context, request *AlterToOptsOptionalExampleRequest) error
type FeaturesExample interface {
Alter(ctx context.Context, request *AlterFeaturesExamplesRequest) error
}

// AlterToOptsOptionalExampleOptions is based on https://example.com.
type AlterToOptsOptionalExampleOptions struct {
// AlterFeaturesExamplesOptions is based on https://example.com.
type AlterFeaturesExamplesOptions struct {
alter bool `ddl:"static" sql:"ALTER"`
IfExists *bool `ddl:"keyword" sql:"IF EXISTS"`
name DatabaseObjectIdentifier `ddl:"identifier"`
OptionalField *OptionalField `ddl:"keyword"`
RequiredField RequiredField `ddl:"keyword"`
}
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved

type OptionalField struct {
SomeList []DatabaseObjectIdentifier `ddl:"list"`
}

type RequiredField struct {
SomeRequiredList []DatabaseObjectIdentifier `ddl:"list"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package example

import "testing"

func TestInt_FeaturesExample(t *testing.T) {
// TODO: prepare common resources

t.Run("Alter", func(t *testing.T) {
// TODO: fill me
})
}
30 changes: 30 additions & 0 deletions pkg/sdk/poc/example/to_opts_optional_example_gen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package example

import "testing"

func TestFeaturesExample_Alter(t *testing.T) {
id := RandomDatabaseObjectIdentifier(t)
// Minimal valid AlterFeaturesExamplesOptions
defaultOpts := func() *AlterFeaturesExamplesOptions {
return &AlterFeaturesExamplesOptions{
name: id,
}
}

t.Run("validation: nil options", func(t *testing.T) {
var opts *AlterFeaturesExamplesOptions = nil
assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions)
})

t.Run("basic", func(t *testing.T) {
opts := defaultOpts()
// TODO: fill me
assertOptsValidAndSQLEquals(t, opts, "TODO: fill me")
})

t.Run("all options", func(t *testing.T) {
opts := defaultOpts()
// TODO: fill me
assertOptsValidAndSQLEquals(t, opts, "TODO: fill me")
})
}
10 changes: 5 additions & 5 deletions pkg/sdk/poc/example/to_opts_optional_example_impl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"context"
)

var _ ToOptsOptionalExamples = (*toOptsOptionalExamples)(nil)
var _ FeaturesExample = (*featuresExample)(nil)
sfc-gh-jmichalak marked this conversation as resolved.
Show resolved Hide resolved

type toOptsOptionalExamples struct {
type featuresExample struct {
client *Client
}

func (v *toOptsOptionalExamples) Alter(ctx context.Context, request *AlterToOptsOptionalExampleRequest) error {
func (v *featuresExample) Alter(ctx context.Context, request *AlterFeaturesExamplesRequest) error {
opts := request.toOpts()
return validateAndExec(v.client, ctx, opts)
}

func (r *AlterToOptsOptionalExampleRequest) toOpts() *AlterToOptsOptionalExampleOptions {
opts := &AlterToOptsOptionalExampleOptions{
func (r *AlterFeaturesExamplesRequest) toOpts() *AlterFeaturesExamplesOptions {
opts := &AlterFeaturesExamplesOptions{
IfExists: r.IfExists,
name: r.name,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package example

import "errors"

var _ validatable = new(AlterToOptsOptionalExampleOptions)
var _ validatable = new(AlterFeaturesExamplesOptions)

func (opts *AlterToOptsOptionalExampleOptions) validate() error {
func (opts *AlterFeaturesExamplesOptions) validate() error {
if opts == nil {
return ErrNilOptions
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sdk/poc/generator/templates/struct.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator.Field*/ -}}

//
sfc-gh-fbudzynski marked this conversation as resolved.
Show resolved Hide resolved
type {{ .KindNoPtr }} struct {
{{- range .Fields }}
{{ .Name }} {{ .Kind }} {{ .TagsPrintable }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{ end }}

{{- if not .IsSlice -}}
opts{{ .Path }} = {{ if .IsPointer }}&{{else}}{{end}}{{ template "toOptsMapping" . -}}{{/* Recursive call */}}
opts{{ .Path }} = {{ if .IsPointer }}&{{end}}{{ template "toOptsMapping" . -}}{{/* Recursive call */}}
{{- else }}
s := make({{ .Kind }}, len(r{{ .Path }}))
for i, v := range r{{ .Path }} {
Expand Down
Loading