Skip to content

Commit

Permalink
Allow creating a Spire Maritime AIS resource instance without a URL f…
Browse files Browse the repository at this point in the history
…lag value (#672)
  • Loading branch information
janelletavares committed Apr 3, 2023
1 parent 05bda8b commit 171a7aa
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
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)) &&
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

0 comments on commit 171a7aa

Please sign in to comment.