Skip to content

Commit

Permalink
Commands: change 'environment inspect' to 'get environment'
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Feb 18, 2023
1 parent 6aa614d commit 22772c6
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmd/kosli/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newEnvironmentCmd(out io.Writer) *cobra.Command {
newEnvironmentLsCmd(out),
newEnvironmentDiffCmd(out),
newAllowedArtifactsCmd(out),
newEnvironmentInspectCmd(out),
newGetEnvironmentCmd(out),
newEnvironmentEventsLogCmd(out),
newEnvironmentGetCmd(out),
newEnvironmentRenameCmd(out),
Expand Down
14 changes: 0 additions & 14 deletions cmd/kosli/environmentCommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,6 @@ func (suite *EnvironmentCommandTestSuite) TestEnvironmentCommandCmd() {
golden: "",
},

// Environment env get tests
{
wantError: false,
name: "kosli env inspect newEnv command does not return error",
cmd: "env inspect newEnv" + defaultKosliArguments,
golden: "",
},
{
wantError: false,
name: "kosli env inspect newEnv --output json command does not return error",
cmd: "env inspect newEnv --output json" + defaultKosliArguments,
golden: "",
},

// Environment rename tests
{
name: "rename: create initial environment",
Expand Down
1 change: 1 addition & 0 deletions cmd/kosli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func newGetCmd(out io.Writer) *cobra.Command {
newGetFlowCmd(out),
newGetArtifactCmd(out),
newGetDeploymentCmd(out),
newGetEnvironmentCmd(out),
)
return cmd
}
2 changes: 1 addition & 1 deletion cmd/kosli/getDeployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (suite *GetDeploymentCommandTestSuite) TestGetDeploymentCmd() {
},
{
wantError: true,
name: "get deployment fails when flow doesn't exist",
name: "get deployment fails when flow does not exist",
cmd: `get deployment foo#1` + suite.defaultKosliArguments,
golden: "Error: Pipeline called 'foo' does not exist for Organization 'docs-cmd-test-user'.\n",
},
Expand Down
19 changes: 10 additions & 9 deletions cmd/kosli/environmentInspect.go → cmd/kosli/getEnvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ import (
"github.com/spf13/cobra"
)

const environmentInspectDesc = `Inspect an environment metadata.`
const getEnvironmentDesc = `Get an environment's metadata.`

type environmentInspectOptions struct {
type getEnvironmentOptions struct {
output string
}

func newEnvironmentInspectCmd(out io.Writer) *cobra.Command {
o := new(environmentInspectOptions)
func newGetEnvironmentCmd(out io.Writer) *cobra.Command {
o := new(getEnvironmentOptions)
cmd := &cobra.Command{
Use: "inspect ENVIRONMENT-NAME",
Short: environmentInspectDesc,
Long: environmentInspectDesc,
Args: cobra.ExactArgs(1),
Use: "environment ENVIRONMENT-NAME",
Aliases: []string{"env"},
Short: getEnvironmentDesc,
Long: getEnvironmentDesc,
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
err := RequireGlobalFlags(global, []string{"Owner", "ApiToken"})
if err != nil {
Expand All @@ -41,7 +42,7 @@ func newEnvironmentInspectCmd(out io.Writer) *cobra.Command {
return cmd
}

func (o *environmentInspectOptions) run(out io.Writer, args []string) error {
func (o *getEnvironmentOptions) run(out io.Writer, args []string) error {
url := fmt.Sprintf("%s/api/v1/environments/%s/%s", global.Host, global.Owner, args[0])

reqParams := &requests.RequestParams{
Expand Down
57 changes: 57 additions & 0 deletions cmd/kosli/getEnvironment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"fmt"
"testing"

log "github.com/kosli-dev/cli/internal/logger"
"github.com/kosli-dev/cli/internal/requests"
"github.com/stretchr/testify/suite"
)

// Define the suite, and absorb the built-in basic suite
// functionality from testify - including a T() method which
// returns the current testing context
type GetEnvironmentCommandTestSuite struct {
suite.Suite
defaultKosliArguments string
flowName string
}

func (suite *GetEnvironmentCommandTestSuite) SetupTest() {
suite.flowName = "github-pr"
global = &GlobalOpts{
ApiToken: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImNkNzg4OTg5In0.e8i_lA_QrEhFncb05Xw6E_tkCHU9QfcY4OLTVUCHffY",
Owner: "docs-cmd-test-user",
Host: "http://localhost:8001",
}
suite.defaultKosliArguments = fmt.Sprintf(" --host %s --owner %s --api-token %s", global.Host, global.Owner, global.ApiToken)
kosliClient = requests.NewKosliClient(1, false, log.NewStandardLogger())

CreateFlow(suite.flowName, suite.T())
}

func (suite *GetEnvironmentCommandTestSuite) TestGetEnvironmentCmd() {
tests := []cmdTestCase{
{
wantError: false,
name: "kosli get env newEnv command does not return error",
cmd: "get env newEnv" + suite.defaultKosliArguments,
golden: "",
},
{
wantError: false,
name: "kosli get env newEnv --output json command does not return error",
cmd: "get environment newEnv --output json" + suite.defaultKosliArguments,
golden: "",
},
}

runTestCmd(suite.T(), tests)
}

// In order for 'go test' to run this suite, we need to create
// a normal test function and pass our suite to suite.Run
func TestGetEnvironmentCommandTestSuite(t *testing.T) {
suite.Run(t, new(GetEnvironmentCommandTestSuite))
}
4 changes: 2 additions & 2 deletions docs.kosli.com/content/getting_started/part_8_querying.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ beta K8S 2022-06-15T11:39:59+02:00 2022-06-15T11:39:59+02:00
prod K8S 2022-06-15T11:40:01+02:00 2022-06-15T11:40:01+02:00
```

And inspect the metadata (including the type) of each environment:
And get the metadata (including the type) of each environment:

```
$ kosli environment inspect aws-beta
$ kosli get environment aws-beta
Name: aws-beta
Type: ECS
Description: The ECS beta namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ production server 2022-08-16T07:53:43+02:00
```

```shell {.command}
kosli environment inspect production
kosli get environment production
```

```plaintext {.light-console}
Expand Down

0 comments on commit 22772c6

Please sign in to comment.