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

Allow creating a Spire Maritime AIS resource instance without a URL f… #672

Merged
merged 1 commit into from
Apr 3, 2023
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
4 changes: 3 additions & 1 deletion cmd/meroxa/root/resources/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ func (c *Create) Execute(ctx context.Context) error {
Metadata: nil,
}

if c.flags.Type != string(meroxa.ResourceTypeNotion) && c.flags.URL == "" {
if (c.flags.Type != string(meroxa.ResourceTypeNotion) &&
c.flags.Type != string(meroxa.ResourceTypeSpireMaritimeAIS)) &&
Copy link
Contributor

@nassor nassor Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a unit test case be added for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing

c.flags.URL == "" {
return fmt.Errorf("required flag(s) \"url\" not set")
}

Expand Down
61 changes: 61 additions & 0 deletions cmd/meroxa/root/resources/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,64 @@ func TestCreateResourceExecutionPrivateKeyFlags(t *testing.T) {
})
}
}

func TestCreateResourceURLFlag(t *testing.T) {
tests := []struct {
description string
resourceType string
client func(*gomock.Controller) *mock.MockClient
wantErr error
}{
{
description: "Do not require URL for Notion",
resourceType: string(meroxa.ResourceTypeNotion),
client: func(ctrl *gomock.Controller) *mock.MockClient {
client := mock.NewMockClient(ctrl)
client.EXPECT().CreateResource(gomock.Any(), gomock.Any()).Return(&meroxa.Resource{}, nil).Times(1)
return client
},
},
{
description: "Do not require URL for Spire Maritime AIS",
resourceType: string(meroxa.ResourceTypeSpireMaritimeAIS),
client: func(ctrl *gomock.Controller) *mock.MockClient {
client := mock.NewMockClient(ctrl)
client.EXPECT().CreateResource(gomock.Any(), gomock.Any()).Return(&meroxa.Resource{}, nil).Times(1)
return client
},
},
{
description: "Require URL for one of the rest of the types",
resourceType: string(meroxa.ResourceTypePostgres),
client: func(ctrl *gomock.Controller) *mock.MockClient {
client := mock.NewMockClient(ctrl)
return client
},
wantErr: fmt.Errorf(`required flag(s) "url" not set`),
},
}

for _, tc := range tests {
t.Run(tc.description, func(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
logger := log.NewTestLogger()
c := &Create{
client: tc.client(ctrl),
logger: logger,
}
c.args.Name = "my-resource"
c.flags.Type = tc.resourceType

err := c.Execute(ctx)
if err != nil {
if tc.wantErr == nil {
t.Fatalf("unexpected error: %v", err)
}
assert.Equal(t, tc.wantErr.Error(), err.Error())
} else {
require.NoError(t, err)
}
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/manifoldco/promptui v0.9.0
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/meroxa/meroxa-go v0.0.0-20230316160201-f7bae0e537fb
github.com/meroxa/meroxa-go v0.0.0-20230331072126-47c9496dfb9b
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lL
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
github.com/meroxa/meroxa-go v0.0.0-20230316160201-f7bae0e537fb h1:eQTWI8puBDJPtIKwOsMwxDExRJ0YK/T+DNCDOUS8dOs=
github.com/meroxa/meroxa-go v0.0.0-20230316160201-f7bae0e537fb/go.mod h1:VaDn0fLKHG2VoI9MQVEqwtfum4BaGr8pcgtfWRe8/Dk=
github.com/meroxa/meroxa-go v0.0.0-20230331072126-47c9496dfb9b h1:xIxLrz8h0QA0QmFZrW3ciIjmEnGDszS/z3yjfD3d+pY=
github.com/meroxa/meroxa-go v0.0.0-20230331072126-47c9496dfb9b/go.mod h1:VaDn0fLKHG2VoI9MQVEqwtfum4BaGr8pcgtfWRe8/Dk=
github.com/meroxa/turbine-core v0.0.0-20230113145603-c7b1554653fa h1:addv/qyR+R6fqHBrJMf4sLp52BAfk4rf88f58aul1hw=
github.com/meroxa/turbine-core v0.0.0-20230113145603-c7b1554653fa/go.mod h1:zhJZykOx6X/L2OKNv8a2P0w7LrwXv3nLh0BLIzfrUh8=
github.com/meroxa/turbine-go v1.0.0 h1:5/mLoRbtdefpcC35fG3YZioz1qgrlaHOKh56n2hJ9lQ=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ github.com/mattn/go-runewidth
# github.com/mattn/go-shellwords v1.0.12
## explicit; go 1.13
github.com/mattn/go-shellwords
# github.com/meroxa/meroxa-go v0.0.0-20230316160201-f7bae0e537fb
# github.com/meroxa/meroxa-go v0.0.0-20230331072126-47c9496dfb9b
## explicit; go 1.20
github.com/meroxa/meroxa-go/pkg/meroxa
github.com/meroxa/meroxa-go/pkg/mock
Expand Down