Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/meroxa/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-cross committed Feb 7, 2022
2 parents 3917e6b + f52bcf0 commit 8e5159f
Show file tree
Hide file tree
Showing 33 changed files with 1,508 additions and 48 deletions.
34 changes: 17 additions & 17 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# Description of change
## Description of change

*A brief description of the change, what it is and why it was made.*
<!-- Provide a brief description of the change, what it is and why it was made below.* -->

Fixes <GitHub Issue>

# Type of change
## Type of change

<!-- Please tick off the correct checkbox after saving the PR description. -->

- [ ] New feature
- [ ] Bug fix
- [ ] Refactor
- [ ] Documentation

# How was this tested?
## How was this tested?

- [ ] Unit Tests
- [ ] Tested in staging

# Demo

**Before this pull-request**

_Include how it looked before_
## Demo

**After this pull-request**
<!-- Provide examples of how the feature looked before and after this change in the table below -->
| before | after |
|--------|-------|
|<!-- Replace this with a screenshot/gif -->|<!-- Replace this with a screenshot/gif -->|

_Include how it looks now_

# Additional references
## Additional references

*Any additional links (if appropriate)*
<!-- Post any additional links (if appropriate) below -->

# Documentation updated
## Documentation updated

*Make sure that our [documentation](https://docs.meroxa.com/) is accordingly updated when necessary.*
<!-- Make sure that our [documentation](https://docs.meroxa.com/) is accordingly updated when necessary.
You can do that by opening a pull-request to our (🔒 private, for now) repository: https://github.com/meroxa/meroxa-docs.
✨ In the future, there will be a GitHub action taking care of these updates automatically. ✨
✨ In the future, there will be a GitHub action taking care of these updates automatically. ✨ -->

*Provide PR link:*
<!-- Provide a PR link below -->
2 changes: 1 addition & 1 deletion cmd/meroxa/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ func buildCommandWithFeatureFlag(cmd *cobra.Command, c Command) {
}
}

flagRequired, err := v.FeatureFlag()
userFeatureFlags := global.Config.GetStringSlice(global.UserFeatureFlagsEnv)
flagRequired, err := v.FeatureFlag()

if !hasFeatureFlag(userFeatureFlags, flagRequired) {
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/meroxa/global/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package global

import (
"errors"
"fmt"
"runtime"
"testing"
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestAddError(t *testing.T) {
}

err := "unexpected error"
addError(event, fmt.Errorf(err))
addError(event, errors.New(err))

if v, ok := event["error"]; !ok || v != err {
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion cmd/meroxa/root/environments/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestCreateEnvironmentExecution(t *testing.T) {
c.flags.Type = "private"
c.flags.Provider = "aws"
c.flags.Region = "aws"
c.flags.Config = []string{"aws_access_key_id=my_access_key", "aws_access_secret=my_access_secret"}
c.flags.Config = []string{"aws_access_key_id=my_access_key", "aws_secret_access_key=my_access_secret"}

cfg := stringSliceToMap(c.flags.Config)

Expand Down
1 change: 1 addition & 0 deletions cmd/meroxa/root/environments/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ func (*Environments) SubCommands() []*cobra.Command {
builder.BuildCobraCommand(&List{}),
builder.BuildCobraCommand(&Remove{}),
builder.BuildCobraCommand(&Update{}),
builder.BuildCobraCommand(&Repair{}),
}
}
2 changes: 1 addition & 1 deletion cmd/meroxa/root/environments/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestListEnvironmentsExecution(t *testing.T) {
Type: meroxa.EnvironmentTypePrivate,
Name: "environment-1234",
Provider: meroxa.EnvironmentProviderAws,
Region: meroxa.EnvironmentRegionUsEast2,
Region: meroxa.EnvironmentRegionUsEast1,
Status: meroxa.EnvironmentViewStatus{State: meroxa.EnvironmentStateProvisioned},
UUID: "531428f7-4e86-4094-8514-d397d49026f7",
}
Expand Down
89 changes: 89 additions & 0 deletions cmd/meroxa/root/environments/repair.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
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 environments

import (
"context"
"errors"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

var (
_ builder.CommandWithDocs = (*Repair)(nil)
_ builder.CommandWithArgs = (*Repair)(nil)
_ builder.CommandWithClient = (*Repair)(nil)
_ builder.CommandWithLogger = (*Repair)(nil)
_ builder.CommandWithExecute = (*Repair)(nil)
_ builder.CommandWithHidden = (*Repair)(nil)
)

type repairEnvironmentClient interface {
PerformActionOnEnvironment(ctx context.Context, nameOrUUID string, body *meroxa.RepairEnvironmentInput) (*meroxa.Environment, error)
}

type Repair struct {
client repairEnvironmentClient
logger log.Logger

args struct {
NameOrUUID string
}
}

func (r *Repair) Hidden() bool {
return true
}

func (r *Repair) Usage() string {
return "repair NAMEorUUID"
}

func (r *Repair) Docs() builder.Docs {
return builder.Docs{
Short: "Repair environment",
Long: `Repair any environment that is in one of the following states: provisioning_error, deprovisioning_error, repairing_error.`,
}
}

func (r *Repair) Logger(logger log.Logger) {
r.logger = logger
}

func (r *Repair) Client(client meroxa.Client) {
r.client = client
}

func (r *Repair) ParseArgs(args []string) error {
if len(args) < 1 {
return errors.New("requires environment name or uuid")
}
r.args.NameOrUUID = args[0]
return nil
}

func (r *Repair) Execute(ctx context.Context) error {
rr, err := r.client.PerformActionOnEnvironment(ctx, r.args.NameOrUUID, &meroxa.RepairEnvironmentInput{Action: meroxa.EnvironmentActionRepair}) // nolint:lll
if err != nil {
return err
}

r.logger.Infof(ctx, `The repairment of your environment %q is now in progress and your environment will be up and running soon.`, r.args.NameOrUUID) // nolint:lll
r.logger.Infof(ctx, `Run "meroxa env describe %s" for status.`, r.args.NameOrUUID)
r.logger.JSON(ctx, rr)

return nil
}
107 changes: 107 additions & 0 deletions cmd/meroxa/root/environments/repair_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
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 environments

import (
"context"
"encoding/json"
"errors"
"strings"

"fmt"
"reflect"
"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 TestRepairEnvironmentArgs(t *testing.T) {
tests := []struct {
args []string
err error
name string
uuid string
}{
{args: nil, err: errors.New("requires environment name or uuid"), name: "", uuid: ""},
{args: []string{"environment-name"}, err: nil, name: "environment-name", uuid: ""},
}

for _, tt := range tests {
cc := &Repair{}
err := cc.ParseArgs(tt.args)

if err != nil && tt.err.Error() != err.Error() {
t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err)
}

if tt.name != cc.args.NameOrUUID {
t.Fatalf("expected \"%s\" got \"%s\"", tt.name, cc.args.NameOrUUID)
}
}
}

func TestRepairEnvironmentExecution(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
client := mock.NewMockClient(ctrl)
logger := log.NewTestLogger()

r := &Repair{
client: client,
logger: logger,
}

e := utils.GenerateEnvironment("")
r.args.NameOrUUID = e.Name

client.
EXPECT().
PerformActionOnEnvironment(ctx, e.Name, &meroxa.RepairEnvironmentInput{Action: "repair"}).
Return(&e, nil)

err := r.Execute(ctx)

if err != nil {
t.Fatalf("not expected error, got \"%s\"", err.Error())
}

gotLeveledOutput := logger.LeveledOutput()
wantLeveledOutput := fmt.Sprintf(
`The repairment of your environment %q is now in progress and your environment will be up and running soon.
Run "meroxa env describe %s" for status.`,
e.Name,
e.Name)

if !strings.Contains(gotLeveledOutput, wantLeveledOutput) {
t.Fatalf("expected output:\n%s\ngot:\n%s", wantLeveledOutput, gotLeveledOutput)
}

gotJSONOutput := logger.JSONOutput()
var gotEnvironment meroxa.Environment
err = json.Unmarshal([]byte(gotJSONOutput), &gotEnvironment)
if err != nil {
t.Fatalf("not expected error, got %q", err.Error())
}

if !reflect.DeepEqual(gotEnvironment, e) {
t.Fatalf("expected \"%v\", got \"%v\"", e, gotEnvironment)
}
}
Loading

0 comments on commit 8e5159f

Please sign in to comment.