-
Notifications
You must be signed in to change notification settings - Fork 5
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
Meroxa builds describe #297
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ Fixes <GitHub Issue> | |
|
||
- [ ] Unit Tests | ||
- [ ] Tested in staging | ||
- [ ] Tested in minikube | ||
|
||
## Demo | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ jobs: | |
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.43.0 | ||
version: v1.45.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright © 2022 Meroxa Inc | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package builds | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/meroxa/cli/cmd/meroxa/builder" | ||
) | ||
|
||
var ( | ||
_ builder.CommandWithDocs = (*Builds)(nil) | ||
_ builder.CommandWithAliases = (*Builds)(nil) | ||
_ builder.CommandWithHidden = (*Builds)(nil) | ||
_ builder.CommandWithFeatureFlag = (*Builds)(nil) | ||
_ builder.CommandWithSubCommands = (*Builds)(nil) | ||
) | ||
|
||
type Builds struct{} | ||
|
||
func (o *Builds) Usage() string { | ||
return "builds" | ||
} | ||
|
||
func (*Builds) Aliases() []string { | ||
return []string{"build"} | ||
} | ||
|
||
func (*Builds) Hidden() bool { | ||
return true | ||
} | ||
|
||
func (*Builds) FeatureFlag() (string, error) { | ||
return "turbine", fmt.Errorf("no access to the Meroxa Data Processes feature") | ||
} | ||
|
||
func (o *Builds) Docs() builder.Docs { | ||
return builder.Docs{ | ||
Short: "Manage Process builds on Meroxa", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here (it should be something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nvm, @janelletavares corrected me that this should be for Processes specifically. Ignore my comment. |
||
} | ||
} | ||
|
||
func (o *Builds) SubCommands() []*cobra.Command { | ||
return []*cobra.Command{ | ||
builder.BuildCobraCommand(&Describe{}), | ||
builder.BuildCobraCommand(&Logs{}), | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Copyright © 2021 Meroxa Inc | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package builds | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/meroxa/cli/cmd/meroxa/builder" | ||
"github.com/meroxa/cli/log" | ||
"github.com/meroxa/cli/utils" | ||
"github.com/meroxa/meroxa-go/pkg/meroxa" | ||
) | ||
|
||
var ( | ||
_ builder.CommandWithDocs = (*Describe)(nil) | ||
_ builder.CommandWithArgs = (*Describe)(nil) | ||
_ builder.CommandWithClient = (*Describe)(nil) | ||
_ builder.CommandWithLogger = (*Describe)(nil) | ||
_ builder.CommandWithExecute = (*Describe)(nil) | ||
) | ||
|
||
type describeBuildClient interface { | ||
GetBuild(ctx context.Context, uuid string) (*meroxa.Build, error) | ||
} | ||
|
||
type Describe struct { | ||
client describeBuildClient | ||
logger log.Logger | ||
|
||
args struct { | ||
UUID string | ||
} | ||
} | ||
|
||
func (d *Describe) Usage() string { | ||
return "describe [UUID]" | ||
} | ||
|
||
func (d *Describe) Docs() builder.Docs { | ||
return builder.Docs{ | ||
Short: "Describe a Meroxa Process Build", | ||
} | ||
} | ||
|
||
func (d *Describe) Execute(ctx context.Context) error { | ||
build, err := d.client.GetBuild(ctx, d.args.UUID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.logger.Info(ctx, utils.BuildTable(build)) | ||
d.logger.JSON(ctx, build) | ||
|
||
return nil | ||
} | ||
|
||
func (d *Describe) Client(client meroxa.Client) { | ||
d.client = client | ||
} | ||
|
||
func (d *Describe) Logger(logger log.Logger) { | ||
d.logger = logger | ||
} | ||
|
||
func (d *Describe) ParseArgs(args []string) error { | ||
if len(args) < 1 { | ||
return errors.New("requires build UUID") | ||
} | ||
|
||
d.args.UUID = args[0] | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Copyright © 2021 Meroxa Inc | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package builds | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/meroxa/cli/log" | ||
"github.com/meroxa/cli/utils" | ||
"github.com/meroxa/meroxa-go/pkg/meroxa" | ||
"github.com/meroxa/meroxa-go/pkg/mock" | ||
) | ||
|
||
func TestDescribeBuildsArgs(t *testing.T) { | ||
tests := []struct { | ||
args []string | ||
err error | ||
name string | ||
}{ | ||
{args: nil, err: errors.New("requires build UUID"), name: ""}, | ||
{args: []string{"BuildUUID"}, err: nil, name: "BuildUUID"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
ar := &Describe{} | ||
err := ar.ParseArgs(tt.args) | ||
|
||
if err != nil && tt.err.Error() != err.Error() { | ||
t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err) | ||
} | ||
|
||
if tt.name != ar.args.UUID { | ||
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, ar.args.UUID) | ||
} | ||
} | ||
} | ||
|
||
func TestDescribeBuildsExecution(t *testing.T) { | ||
ctx := context.Background() | ||
ctrl := gomock.NewController(t) | ||
client := mock.NewMockClient(ctrl) | ||
logger := log.NewTestLogger() | ||
|
||
a := utils.GenerateBuild() | ||
|
||
client. | ||
EXPECT(). | ||
GetBuild( | ||
ctx, | ||
a.Uuid, | ||
). | ||
Return(&a, nil) | ||
|
||
dc := &Describe{ | ||
client: client, | ||
logger: logger, | ||
} | ||
dc.args.UUID = a.Uuid | ||
|
||
err := dc.Execute(ctx) | ||
if err != nil { | ||
t.Fatalf("not expected error, got %q", err.Error()) | ||
} | ||
|
||
gotLeveledOutput := logger.LeveledOutput() | ||
wantLeveledOutput := utils.BuildTable(&a) | ||
|
||
if !strings.Contains(gotLeveledOutput, wantLeveledOutput) { | ||
t.Fatalf("expected output:\n%s\ngot:\n%s", wantLeveledOutput, gotLeveledOutput) | ||
} | ||
|
||
gotJSONOutput := logger.JSONOutput() | ||
var gotBuild meroxa.Build | ||
err = json.Unmarshal([]byte(gotJSONOutput), &gotBuild) | ||
if err != nil { | ||
t.Fatalf("not expected error, got %q", err.Error()) | ||
} | ||
|
||
if !reflect.DeepEqual(gotBuild, a) { | ||
t.Fatalf("expected \"%v\", got \"%v\"", a, gotBuild) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
Copyright © 2021 Meroxa Inc | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package builds | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/meroxa/cli/cmd/meroxa/builder" | ||
"github.com/meroxa/cli/log" | ||
"github.com/meroxa/meroxa-go/pkg/meroxa" | ||
) | ||
|
||
var ( | ||
_ builder.CommandWithDocs = (*Logs)(nil) | ||
_ builder.CommandWithArgs = (*Logs)(nil) | ||
_ builder.CommandWithClient = (*Logs)(nil) | ||
_ builder.CommandWithLogger = (*Logs)(nil) | ||
_ builder.CommandWithExecute = (*Logs)(nil) | ||
) | ||
|
||
type buildLogsClient interface { | ||
GetBuildLogs(ctx context.Context, uuid string) (*http.Response, error) | ||
} | ||
|
||
type Logs struct { | ||
client buildLogsClient | ||
logger log.Logger | ||
|
||
args struct { | ||
UUID string | ||
} | ||
} | ||
|
||
func (d *Logs) Usage() string { | ||
return "logs [UUID]" | ||
} | ||
|
||
func (d *Logs) Docs() builder.Docs { | ||
return builder.Docs{ | ||
Short: "List a Meroxa Process Build's Logs", | ||
} | ||
} | ||
|
||
func (d *Logs) Execute(ctx context.Context) error { | ||
response, err := d.client.GetBuildLogs(ctx, d.args.UUID) | ||
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() | ||
|
||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.logger.Info(ctx, string(body)) | ||
|
||
return nil | ||
} | ||
|
||
func (d *Logs) Client(client meroxa.Client) { | ||
d.client = client | ||
} | ||
|
||
func (d *Logs) Logger(logger log.Logger) { | ||
d.logger = logger | ||
} | ||
|
||
func (d *Logs) ParseArgs(args []string) error { | ||
if len(args) < 1 { | ||
return errors.New("requires build UUID") | ||
} | ||
|
||
d.args.UUID = args[0] | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericcheatham I think
Processes
was a typo here, right? (it should beMeroxa Data Applications
)