Skip to content

Commit

Permalink
Update CLI e2e tests for more resources (#2683)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbdias committed Jun 13, 2023
1 parent 84f4e11 commit 2e629ff
Show file tree
Hide file tree
Showing 41 changed files with 1,599 additions and 183 deletions.
2 changes: 1 addition & 1 deletion cli/actions/config.go
Expand Up @@ -55,5 +55,5 @@ func (config configActions) List(ctx context.Context, listArgs utils.ListArgs) (
}

func (config configActions) Delete(ctx context.Context, ID string) (string, error) {
return "Config successfully reset to default", ErrNotSupportedResourceAction
return "", ErrNotSupportedResourceAction // we don't have support to delete config today
}
5 changes: 4 additions & 1 deletion cli/actions/demo.go
Expand Up @@ -42,7 +42,10 @@ func (demo demoActions) GetID(file *file.File) (string, error) {
}

func (demo demoActions) Apply(ctx context.Context, fileContent file.File) (result *file.File, err error) {
var demoResource openapi.Demo
demoResource := openapi.Demo{
Spec: &openapi.DemoSpec{},
}

mapstructure.Decode(fileContent.Definition().Spec, &demoResource.Spec)

if demoResource.Spec.Id == nil || *demoResource.Spec.Id == "" {
Expand Down
4 changes: 0 additions & 4 deletions cli/actions/polling.go
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/kubeshop/tracetest/cli/openapi"
"github.com/kubeshop/tracetest/cli/utils"
"github.com/kubeshop/tracetest/server/model/yaml"
"github.com/mitchellh/mapstructure"
)

type pollingActions struct {
Expand Down Expand Up @@ -42,9 +41,6 @@ func (polling pollingActions) GetID(file *file.File) (string, error) {
}

func (polling pollingActions) Apply(ctx context.Context, fileContent file.File) (result *file.File, err error) {
var pollingProfile openapi.PollingProfile
mapstructure.Decode(fileContent.Definition().Spec, &pollingProfile.Spec)

result, err = polling.resourceClient.Update(ctx, fileContent, currentConfigID)
return result, err
}
Expand Down
17 changes: 8 additions & 9 deletions cli/formatters/config.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/alexeyco/simpletable"
"github.com/goccy/go-yaml"
"github.com/kubeshop/tracetest/cli/file"
"github.com/kubeshop/tracetest/cli/openapi"
)
Expand Down Expand Up @@ -55,28 +56,26 @@ func (f ConfigFormatter) ToListTable(file *file.File) (*simpletable.Header, *sim
}

func (f ConfigFormatter) ToStruct(file *file.File) (interface{}, error) {
var ConfigResource openapi.ConfigurationResource
nullableConfig := openapi.NewNullableConfigurationResource(&ConfigResource)
var configResource openapi.ConfigurationResource

err := nullableConfig.UnmarshalJSON([]byte(file.Contents()))
err := yaml.Unmarshal([]byte(file.Contents()), &configResource)
if err != nil {
return nil, err
}

return ConfigResource, nil
return configResource, nil
}

func (f ConfigFormatter) ToListStruct(file *file.File) ([]interface{}, error) {
var ConfigResourceList openapi.ConfigurationResourceList
nullableList := openapi.NewNullableConfigurationResourceList(&ConfigResourceList)
var configList openapi.ConfigurationResourceList

err := nullableList.UnmarshalJSON([]byte(file.Contents()))
err := yaml.Unmarshal([]byte(file.Contents()), &configList)
if err != nil {
return nil, err
}

items := make([]interface{}, len(ConfigResourceList.Items))
for i, item := range ConfigResourceList.Items {
items := make([]interface{}, len(configList.Items))
for i, item := range configList.Items {
items[i] = item
}

Expand Down
7 changes: 3 additions & 4 deletions cli/formatters/demo.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/alexeyco/simpletable"
"github.com/goccy/go-yaml"
"github.com/kubeshop/tracetest/cli/file"
"github.com/kubeshop/tracetest/cli/openapi"
)
Expand Down Expand Up @@ -56,9 +57,8 @@ func (f DemoFormatter) ToListTable(file *file.File) (*simpletable.Header, *simpl

func (f DemoFormatter) ToStruct(file *file.File) (interface{}, error) {
var demoResource openapi.Demo
nullableDemo := openapi.NewNullableDemo(&demoResource)

err := nullableDemo.UnmarshalJSON([]byte(file.Contents()))
err := yaml.Unmarshal([]byte(file.Contents()), &demoResource)
if err != nil {
return nil, err
}
Expand All @@ -68,9 +68,8 @@ func (f DemoFormatter) ToStruct(file *file.File) (interface{}, error) {

func (f DemoFormatter) ToListStruct(file *file.File) ([]interface{}, error) {
var demoList openapi.DemoList
nullableList := openapi.NewNullableDemoList(&demoList)

err := nullableList.UnmarshalJSON([]byte(file.Contents()))
err := yaml.Unmarshal([]byte(file.Contents()), &demoList)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions cli/formatters/environment.go
Expand Up @@ -66,9 +66,8 @@ func (f EnvironmentsFormatter) ToStruct(file *file.File) (interface{}, error) {

func (f EnvironmentsFormatter) ToListStruct(file *file.File) ([]interface{}, error) {
var environmentResourceList openapi.EnvironmentResourceList
nullableList := openapi.NewNullableEnvironmentResourceList(&environmentResourceList)

err := nullableList.UnmarshalJSON([]byte(file.Contents()))
err := yaml.Unmarshal([]byte(file.Contents()), &environmentResourceList)
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions cli/formatters/polling.go
Expand Up @@ -2,6 +2,7 @@ package formatters

import (
"github.com/alexeyco/simpletable"
"github.com/goccy/go-yaml"
"github.com/kubeshop/tracetest/cli/file"
"github.com/kubeshop/tracetest/cli/openapi"
)
Expand Down Expand Up @@ -54,9 +55,8 @@ func (f PollingFormatter) ToListTable(file *file.File) (*simpletable.Header, *si

func (f PollingFormatter) ToStruct(file *file.File) (interface{}, error) {
var pollingResource openapi.PollingProfile
nullablePolling := openapi.NewNullablePollingProfile(&pollingResource)

err := nullablePolling.UnmarshalJSON([]byte(file.Contents()))
err := yaml.Unmarshal([]byte(file.Contents()), &pollingResource)
if err != nil {
return nil, err
}
Expand All @@ -66,9 +66,8 @@ func (f PollingFormatter) ToStruct(file *file.File) (interface{}, error) {

func (f PollingFormatter) ToListStruct(file *file.File) ([]interface{}, error) {
var pollingProfileList openapi.PollingProfileList
nullableList := openapi.NewNullablePollingProfileList(&pollingProfileList)

err := nullableList.UnmarshalJSON([]byte(file.Contents()))
err := yaml.Unmarshal([]byte(file.Contents()), &pollingProfileList)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion server/executor/pollingprofile/polling_profile_resource.go
Expand Up @@ -236,7 +236,7 @@ func (r *Repository) Count(ctx context.Context, query string) (int, error) {
}

func (*Repository) SortingFields() []string {
return []string{}
return []string{"name"}
}

func (r *Repository) Provision(ctx context.Context, profile PollingProfile) error {
Expand Down
7 changes: 6 additions & 1 deletion testing/cli-e2etest/Makefile
@@ -1,6 +1,7 @@
TRACETEST_CLI?="../../dist/tracetest"
TEST_ENVIRONMENT?="jaeger"
TAG?="dev"
ENABLE_CLI_DEBUG?="false"

help: Makefile ## show list of commands
@echo "Choose a command run:"
Expand All @@ -9,4 +10,8 @@ help: Makefile ## show list of commands

test: # run tests for this application
go clean -testcache
go test -v -timeout 300s -p 1 ./...
go test -timeout 300s -p 1 ./...

test/debug: # run tests for this application with debug mode enabled
ENABLE_CLI_DEBUG="true"
make test
99 changes: 58 additions & 41 deletions testing/cli-e2etest/README.md
Expand Up @@ -42,23 +42,24 @@ The main idea is to test every CLI command against the Tracetest server with dif

| CLI Command | Test scenarios |
| ----------------------------------------------------- | -------------- |
| `apply config -f [config-file]` | |
| `delete config --id current` | |
| `get config --id current --output pretty` | |
| `get config --id current --output json` | |
| `get config --id current --output yaml` | |
| `list config --output pretty` | |
| `list config --output json` | |
| `list config --output yaml` | |
| `apply config -f [config-file]` | [ApplyConfig](./testscenarios/config/apply_config_test.go) |
| `delete config --id current` | [DeleteConfig](./testscenarios/config/delete_config_test.go) |
| `get config --id current --output pretty` | [GetConfig](./testscenarios/config/get_config_test.go), [ApplyConfig](./testscenarios/config/apply_config_test.go), [DeleteConfig](./testscenarios/config/delete_config_test.go) |
| `get config --id current --output json` | [GetConfig](./testscenarios/config/get_config_test.go) |
| `get config --id current --output yaml` | [GetConfig](./testscenarios/config/get_config_test.go) |
| `list config --output pretty` | [ListConfig](./testscenarios/config/list_config_test.go) |
| `list config --output json` | [ListConfig](./testscenarios/config/list_config_test.go) |
| `list config --output yaml` | [ListConfig](./testscenarios/config/list_config_test.go) |

### Resources: Data Store

| CLI Command | Test scenarios |
| -------------------------------------------------------- | -------------- |
| `apply datastore -f [data-store-file]` | [ApplyNewDatastore](./testscenarios/datastore/apply_new_datastore_test.go) |
| `apply datastore -f [data-store-file]` | [ApplyDatastore](./testscenarios/datastore/apply_datastore_test.go) |
| `delete datastore --id current` | [DeleteDatastore](./testscenarios/datastore/delete_datastore_test.go) |
| `get datastore --id current --output pretty` | [ApplyNewDatastore](./testscenarios/datastore/apply_new_datastore_test.go), [DeleteDatastore](./testscenarios/datastore/delete_datastore_test.go) |
| `get datastore --id current --output json` | |
| `get datastore --id current --output yaml` | |
| `get datastore --id current --output pretty` | [GetDatastore](./testscenarios/datastore/get_datastore_test.go), [ApplyDatastore](./testscenarios/datastore/apply_datastore_test.go), [DeleteDatastore](./testscenarios/datastore/delete_datastore_test.go) |
| `get datastore --id current --output json` | [GetDatastore](./testscenarios/datastore/get_datastore_test.go) |
| `get datastore --id current --output yaml` | [GetDatastore](./testscenarios/datastore/get_datastore_test.go) |
| `list datastore --output pretty` | [ListDatastore](./testscenarios/datastore/list_datastore_test.go) |
| `list datastore --output json` | [ListDatastore](./testscenarios/datastore/list_datastore_test.go) |
| `list datastore --output yaml` | [ListDatastore](./testscenarios/datastore/list_datastore_test.go) |
Expand All @@ -67,32 +68,32 @@ The main idea is to test every CLI command against the Tracetest server with dif

| CLI Command | Test scenarios |
| ---------------------------------------------------- | -------------- |
| `apply demo -f [new-demo-file]` | |
| `apply demo -f [existing-demo-file]` | |
| `delete demo --id [existing-id]` | |
| `delete demo --id [non-existing-id]` | |
| `get demo --id [non-existing-id]` | |
| `get demo --id [existing-id] --output pretty` | |
| `get demo --id [existing-id] --output json` | |
| `get demo --id [existing-id] --output yaml` | |
| `list demo --output pretty` | |
| `list demo --output json` | |
| `list demo --output yaml` | |
| `list demo --skip 1 --take 2` | |
| `list demo --sortBy name --sortDirection asc` | |
| `apply demo -f [new-demo-file]` | [ApplyDemo](./testscenarios/demo/apply_demo_test.go) |
| `apply demo -f [existing-demo-file]` | [ApplyDemo](./testscenarios/demo/apply_demo_test.go) |
| `delete demo --id [existing-id]` | [DeleteDemo](./testscenarios/demo/delete_demo_test.go) |
| `delete demo --id [non-existing-id]` | [DeleteDemo](./testscenarios/demo/delete_demo_test.go) |
| `get demo --id [non-existing-id]` | [GetDemo](./testscenarios/demo/get_demo_test.go), [DeleteDemo](./testscenarios/demo/delete_demo_test.go) |
| `get demo --id [existing-id] --output pretty` | [GetDemo](./testscenarios/demo/get_demo_test.go) |
| `get demo --id [existing-id] --output json` | [GetDemo](./testscenarios/demo/get_demo_test.go) |
| `get demo --id [existing-id] --output yaml` | [GetDemo](./testscenarios/demo/get_demo_test.go) |
| `list demo --output pretty` | [ListDemo](./testscenarios/demo/list_demos_test.go) |
| `list demo --output json` | [ListDemo](./testscenarios/demo/list_demos_test.go) |
| `list demo --output yaml` | [ListDemo](./testscenarios/demo/list_demos_test.go) |
| `list demo --skip 1 --take 1` | [ListDemo](./testscenarios/demo/list_demos_test.go) |
| `list demo --sortBy name --sortDirection asc` | [ListDemo](./testscenarios/demo/list_demos_test.go) |

### Resources: Environment

| CLI Command | Test scenarios |
| ----------------------------------------------------------- | -------------- |
| `apply environment -f [new-environment-file]` | [ApplyNewEnvironment](./testscenarios/environment/apply_new_environment_test.go) |
| `apply environment -f [existing-environment-file]` | [ApplyNewEnvironment](./testscenarios/environment/apply_new_environment_test.go) |
| `apply environment -f [new-environment-file]` | [ApplyEnvironment](./testscenarios/environment/apply_environment_test.go) |
| `apply environment -f [existing-environment-file]` | [ApplyEnvironment](./testscenarios/environment/apply_environment_test.go) |
| `delete environment --id [existing-id]` | [DeleteEnvironment](./testscenarios/environment/delete_environment_test.go) |
| `delete environment --id [non-existing-id]` | [DeleteEnvironment](./testscenarios/environment/delete_environment_test.go) |
| `get environment --id [non-existing-id]` | [DeleteEnvironment](./testscenarios/environment/delete_environment_test.go) |
| `get environment --id [existing-id] --output pretty` | |
| `get environment --id [existing-id] --output json` | |
| `get environment --id [existing-id] --output yaml` | [ApplyNewEnvironment](./testscenarios/environment/apply_new_environment_test.go) |
| `get environment --id [non-existing-id]` | [GetEnvironment](./testscenarios/environment/get_environment_test.go), [DeleteEnvironment](./testscenarios/environment/delete_environment_test.go) |
| `get environment --id [existing-id] --output pretty` | [GetEnvironment](./testscenarios/environment/get_environment_test.go) |
| `get environment --id [existing-id] --output json` | [GetEnvironment](./testscenarios/environment/get_environment_test.go) |
| `get environment --id [existing-id] --output yaml` | [GetEnvironment](./testscenarios/environment/get_environment_test.go) |
| `list environment --output pretty` | [ListEnvironment](./testscenarios/environment/list_environments_test.go) |
| `list environment --output json` | [ListEnvironment](./testscenarios/environment/list_environments_test.go) |
| `list environment --output yaml` | [ListEnvironment](./testscenarios/environment/list_environments_test.go) |
Expand All @@ -103,15 +104,14 @@ The main idea is to test every CLI command against the Tracetest server with dif

| CLI Command | Test scenarios |
| --------------------------------------------------------------------- | -------------- |
| `apply pollingprofile -f [pollingprofile-file]` | |
| `delete pollingprofile --id current` | |
| `export pollingprofile --id current --file [pollingprofile-file]` | |
| `get pollingprofile --id current --output pretty` | |
| `get pollingprofile --id current --output json` | |
| `get pollingprofile --id current --output yaml` | |
| `list pollingprofile --output pretty` | |
| `list pollingprofile --output json` | |
| `list pollingprofile --output yaml` | |
| `apply pollingprofile -f [pollingprofile-file]` | [ApplyPollingProfile](./testscenarios/pollingprofile/apply_pollingprofile_test.go) |
| `delete pollingprofile --id current` | [DeletePollingProfile](./testscenarios/pollingprofile/delete_pollingprofile_test.go) |
| `get pollingprofile --id current --output pretty` | [GetPollingProfile](./testscenarios/pollingprofile/get_pollingprofile_test.go), [ApplyPollingProfile](./testscenarios/pollingprofile/apply_pollingprofile_test.go), [DeletePollingProfile](./testscenarios/pollingprofile/delete_pollingprofile_test.go) |
| `get pollingprofile --id current --output json` | [GetPollingProfile](./testscenarios/pollingprofile/get_pollingprofile_test.go) |
| `get pollingprofile --id current --output yaml` | [GetPollingProfile](./testscenarios/pollingprofile/get_pollingprofile_test.go) |
| `list pollingprofile --output pretty` | [ListPollingProfile](./testscenarios/pollingprofile/list_pollingprofile_test.go) |
| `list pollingprofile --output json` | [ListPollingProfile](./testscenarios/pollingprofile/list_pollingprofile_test.go) |
| `list pollingprofile --output yaml` | [ListPollingProfile](./testscenarios/pollingprofile/list_pollingprofile_test.go) |

### Resources: Transactions

Expand All @@ -121,7 +121,6 @@ The main idea is to test every CLI command against the Tracetest server with dif
| `apply transaction -f [existing-transaction-file]` | |
| `delete transaction --id [existing-id]` | |
| `delete transaction --id [non-existing-id]` | |
| `export transaction --id current --file [transaction-file]` | |
| `get transaction --id [non-existing-id]` | |
| `get transaction --id [existing-id] --output pretty` | |
| `get transaction --id [existing-id] --output json` | |
Expand All @@ -131,3 +130,21 @@ The main idea is to test every CLI command against the Tracetest server with dif
| `list transaction --output yaml` | |
| `list transaction --skip 1 --take 2` | |
| `list transaction --sortBy name --sortDirection asc` | |

### Resources: Tests

| CLI Command | Test scenarios |
| ----------------------------------------------------------- | -------------- |
| `apply test -f [new-test-file]` | |
| `apply test -f [existing-test-file]` | |
| `delete test --id [existing-id]` | |
| `delete test --id [non-existing-id]` | |
| `get test --id [non-existing-id]` | |
| `get test --id [existing-id] --output pretty` | |
| `get test --id [existing-id] --output json` | |
| `get test --id [existing-id] --output yaml` | |
| `list test --output pretty` | |
| `list test --output json` | |
| `list test --output yaml` | |
| `list test --skip 1 --take 2` | |
| `list test --sortBy name --sortDirection asc` | |

0 comments on commit 2e629ff

Please sign in to comment.