Skip to content
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

Improve test output and remove parallelism #2575

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testing/cli-e2etest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ help: Makefile ## show list of commands

test: # run tests for this application
go clean -testcache
go test -timeout 150s ./...
go test -timeout 150s -p 1 ./...
11 changes: 3 additions & 8 deletions testing/cli-e2etest/environment/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/kubeshop/tracetest/cli-e2etest/command"
"github.com/kubeshop/tracetest/cli-e2etest/config"
"github.com/kubeshop/tracetest/cli-e2etest/helpers"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)
Expand All @@ -37,8 +38,6 @@ type internalManager struct {
}

func CreateAndStart(t *testing.T) Manager {
t.Helper()

mutex.Lock()
defer mutex.Unlock()

Expand Down Expand Up @@ -85,24 +84,20 @@ func (m *internalManager) Name() string {
}

func (m *internalManager) Start(t *testing.T) {
t.Helper()

result, err := command.Exec(
"docker", "compose",
"--file", m.dockerComposeFilePath, // choose docker compose relative to the chosen environment
"--project-name", m.dockerProjectName, // create a project name to isolate this scenario
"up", "--detach")

require.NoError(t, err)
require.Equal(t, 0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

// TODO: think in a better way to assure readiness for Tracetest
time.Sleep(1000 * time.Millisecond)
}

func (m *internalManager) Close(t *testing.T) {
t.Helper()

result, err := command.Exec(
"docker", "compose",
"--file", m.dockerComposeFilePath, // choose docker compose relative to the chosen environment
Expand All @@ -113,7 +108,7 @@ func (m *internalManager) Close(t *testing.T) {
"--stop", // force containers to stop
)
require.NoError(t, err)
require.Equal(t, 0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)
}

func (m *internalManager) GetCLIConfigPath(t *testing.T) string {
Expand Down
9 changes: 9 additions & 0 deletions testing/cli-e2etest/helpers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/goccy/go-yaml"
"github.com/kubeshop/tracetest/cli-e2etest/command"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -49,3 +50,11 @@ func UnmarshalYAMLSequence[T any](t *testing.T, data string) []T {

return result
}

func RequireExitCodeEqual(t *testing.T, result *command.ExecResult, expectedExitCode int) {
require.Equal(
t, expectedExitCode, result.ExitCode,
"command %s finished with wrong exit code. Expected code: %d Obtained code: %d \nStdOut: %s \nStdErr: %s",
result.CommandExecuted, expectedExitCode, result.ExitCode, result.StdOut, result.StdErr,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestApplyNewDatastore(t *testing.T) {
// Then it should return an empty datastore
result := tracetestcli.Exec(t, "get datastore --id current", tracetestcli.WithCLIConfig(cliConfig))
// TODO: we haven't defined a valid output to tell to the user that we are on `no-tracing mode`
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

dataStore := helpers.UnmarshalYAML[types.DataStoreResource](t, result.StdOut)
require.Equal("DataStore", dataStore.Type)
Expand All @@ -39,12 +39,12 @@ func TestApplyNewDatastore(t *testing.T) {
dataStorePath := env.GetEnvironmentResourcePath(t, "data-store")

result = tracetestcli.Exec(t, fmt.Sprintf("apply datastore --file %s", dataStorePath), tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

// When I try to get a datastore again
// Then it should return the datastore applied on the last step
result = tracetestcli.Exec(t, "get datastore --id current", tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

dataStore = helpers.UnmarshalYAML[types.DataStoreResource](t, result.StdOut)
require.Equal("DataStore", dataStore.Type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func TestDeleteDatastore(t *testing.T) {
dataStorePath := env.GetEnvironmentResourcePath(t, "data-store")

result := tracetestcli.Exec(t, fmt.Sprintf("apply datastore --file %s", dataStorePath), tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

// When I try to get a datastore
// Then it should return the datastore applied on the last step
result = tracetestcli.Exec(t, "get datastore --id current", tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

dataStore := helpers.UnmarshalYAML[types.DataStoreResource](t, result.StdOut)
require.Equal("DataStore", dataStore.Type)
Expand All @@ -44,14 +44,14 @@ func TestDeleteDatastore(t *testing.T) {
// When I try to delete the datastore
// Then it should delete with success
result = tracetestcli.Exec(t, "delete datastore --id current", tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "DataStore removed. Defaulting back to no-tracing mode")

// When I try to get a datastore again
// Then it should return an empty datastore
result = tracetestcli.Exec(t, "get datastore --id current", tracetestcli.WithCLIConfig(cliConfig))
// TODO: we haven't defined a valid output to tell to the user that we are on `no-tracing mode`
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

dataStore = helpers.UnmarshalYAML[types.DataStoreResource](t, result.StdOut)
require.Equal("DataStore", dataStore.Type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func TestListDatastore(t *testing.T) {
dataStorePath := env.GetEnvironmentResourcePath(t, "data-store")

result := tracetestcli.Exec(t, fmt.Sprintf("apply datastore --file %s", dataStorePath), tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

// When I try to list datastore again on pretty mode
// Then it should print a table with 4 lines printed: header, separator, data store item and empty line
result = tracetestcli.Exec(t, "list datastore --output pretty", tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "current")
require.Contains(result.StdOut, env.Name())

Expand All @@ -44,7 +44,7 @@ func TestListDatastore(t *testing.T) {
// When I try to list datastore again on json mode
// Then it should print a JSON list with one item
result = tracetestcli.Exec(t, "list datastore --output json", tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)

dataStoresJSON := helpers.UnmarshalJSON[[]types.DataStoreResource](t, result.StdOut)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/kubeshop/tracetest/cli-e2etest/environment"
"github.com/kubeshop/tracetest/cli-e2etest/helpers"
"github.com/kubeshop/tracetest/cli-e2etest/tracetestcli"
"github.com/stretchr/testify/require"
)
Expand All @@ -24,7 +25,7 @@ func TestApplyNewEnvironment(t *testing.T) {
// When I try to get an environment that doesn't exists
// Then it should return error message
result := tracetestcli.Exec(t, "get environment --id .noenv", tracetestcli.WithCLIConfig(cliConfig))
require.Equal(0, result.ExitCode)
helpers.RequireExitCodeEqual(t, result, 0)
require.Contains(result.StdOut, "Resource environment with ID .noenv not found")

// When I try to set up a new environment
Expand Down