-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/meroxa/cli
- Loading branch information
Showing
33 changed files
with
1,508 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.