-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI e2e test for transaction resource (#2757)
* Adding example of transactions * Adding run test for transactions * Adding Apply test for Transactions * Adding delete test * Adding list test * Fixing OpenAPI def that was causing our JSON marshaller to skip transaction id * Adding Makefile commands into the same shell session to recognize env vars * Fixing run transaction scenario * Update transaction test
- Loading branch information
1 parent
bbb642c
commit cf4c251
Showing
24 changed files
with
804 additions
and
140 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 |
---|---|---|
|
@@ -29,7 +29,6 @@ components: | |
properties: | ||
id: | ||
type: string | ||
readOnly: true | ||
name: | ||
type: string | ||
description: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
88 changes: 88 additions & 0 deletions
88
testing/cli-e2etest/testscenarios/transaction/apply_transaction_test.go
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,88 @@ | ||
package transaction | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/kubeshop/tracetest/cli-e2etest/environment" | ||
"github.com/kubeshop/tracetest/cli-e2etest/helpers" | ||
"github.com/kubeshop/tracetest/cli-e2etest/testscenarios/types" | ||
"github.com/kubeshop/tracetest/cli-e2etest/tracetestcli" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestApplyTransaction(t *testing.T) { | ||
// instantiate require with testing helper | ||
require := require.New(t) | ||
|
||
// setup isolated e2e environment | ||
env := environment.CreateAndStart(t) | ||
defer env.Close(t) | ||
|
||
cliConfig := env.GetCLIConfigPath(t) | ||
|
||
// Given I am a Tracetest CLI user | ||
// And I have my server recently created | ||
|
||
// When I try to set up a new transaction | ||
// Then it should be applied with success | ||
newTransactionPath := env.GetTestResourcePath(t, "new-transaction") | ||
|
||
result := tracetestcli.Exec(t, fmt.Sprintf("apply transaction --file %s", newTransactionPath), tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
|
||
transaction := helpers.UnmarshalYAML[types.TransactionResource](t, result.StdOut) | ||
|
||
require.Equal("Transaction", transaction.Type) | ||
require.Equal("Qti5R3_VR", transaction.Spec.ID) | ||
require.Equal("New Transaction", transaction.Spec.Name) | ||
require.Equal("a transaction", transaction.Spec.Description) | ||
require.Len(transaction.Spec.Steps, 2) | ||
require.Equal("9wtAH2_Vg", transaction.Spec.Steps[0]) | ||
require.Equal("ajksdkasjbd", transaction.Spec.Steps[1]) | ||
|
||
// When I try to get the transaction applied on the last step | ||
// Then it should return it | ||
result = tracetestcli.Exec(t, "get transaction --id Qti5R3_VR --output yaml", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
|
||
require.Equal("Transaction", transaction.Type) | ||
require.Equal("Qti5R3_VR", transaction.Spec.ID) | ||
require.Equal("New Transaction", transaction.Spec.Name) | ||
require.Equal("a transaction", transaction.Spec.Description) | ||
require.Len(transaction.Spec.Steps, 2) | ||
require.Equal("9wtAH2_Vg", transaction.Spec.Steps[0]) | ||
require.Equal("ajksdkasjbd", transaction.Spec.Steps[1]) | ||
|
||
// When I try to update the last transaction | ||
// Then it should be applied with success | ||
updatedNewTransactionPath := env.GetTestResourcePath(t, "updated-new-transaction") | ||
|
||
result = tracetestcli.Exec(t, fmt.Sprintf("apply transaction --file %s", updatedNewTransactionPath), tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
|
||
updatedTransaction := helpers.UnmarshalYAML[types.TransactionResource](t, result.StdOut) | ||
require.Equal("Transaction", updatedTransaction.Type) | ||
require.Equal("Qti5R3_VR", updatedTransaction.Spec.ID) | ||
require.Equal("Updated Transaction", updatedTransaction.Spec.Name) | ||
require.Equal("an updated transaction", updatedTransaction.Spec.Description) | ||
require.Len(updatedTransaction.Spec.Steps, 3) | ||
require.Equal("9wtAH2_Vg", updatedTransaction.Spec.Steps[0]) | ||
require.Equal("ajksdkasjbd", updatedTransaction.Spec.Steps[1]) | ||
require.Equal("ajksdkasjbd", updatedTransaction.Spec.Steps[2]) | ||
|
||
// When I try to get the transaction applied on the last step | ||
// Then it should return it | ||
result = tracetestcli.Exec(t, "get transaction --id Qti5R3_VR --output yaml", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
|
||
updatedTransaction = helpers.UnmarshalYAML[types.TransactionResource](t, result.StdOut) | ||
require.Equal("Transaction", updatedTransaction.Type) | ||
require.Equal("Qti5R3_VR", updatedTransaction.Spec.ID) | ||
require.Equal("Updated Transaction", updatedTransaction.Spec.Name) | ||
require.Equal("an updated transaction", updatedTransaction.Spec.Description) | ||
require.Len(updatedTransaction.Spec.Steps, 3) | ||
require.Equal("9wtAH2_Vg", updatedTransaction.Spec.Steps[0]) | ||
require.Equal("ajksdkasjbd", updatedTransaction.Spec.Steps[1]) | ||
require.Equal("ajksdkasjbd", updatedTransaction.Spec.Steps[2]) | ||
} |
50 changes: 50 additions & 0 deletions
50
testing/cli-e2etest/testscenarios/transaction/delete_transaction_test.go
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,50 @@ | ||
package transaction | ||
|
||
import ( | ||
"fmt" | ||
"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" | ||
) | ||
|
||
func TestDeleteTransaction(t *testing.T) { | ||
// instantiate require with testing helper | ||
require := require.New(t) | ||
|
||
// setup isolated e2e environment | ||
env := environment.CreateAndStart(t) | ||
defer env.Close(t) | ||
|
||
cliConfig := env.GetCLIConfigPath(t) | ||
|
||
// Given I am a Tracetest CLI user | ||
// And I have my server recently created | ||
|
||
// When I try to delete a transaction that don't exist | ||
// Then it should return an error and say that this resource does not exist | ||
result := tracetestcli.Exec(t, "delete transaction --id dont-exist", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 1) | ||
require.Contains(result.StdErr, "Resource transactions with ID dont-exist not found") // TODO: update this message to singular | ||
|
||
// When I try to set up a new transaction | ||
// Then it should be applied with success | ||
newTransactionPath := env.GetTestResourcePath(t, "new-transaction") | ||
|
||
result = tracetestcli.Exec(t, fmt.Sprintf("apply transaction --file %s", newTransactionPath), tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
|
||
// When I try to delete the transaction | ||
// Then it should delete with success | ||
result = tracetestcli.Exec(t, "delete transaction --id Qti5R3_VR", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
require.Contains(result.StdOut, "✔ Transaction successfully deleted") | ||
|
||
// When I try to get a transaction again | ||
// Then it should return a message saying that the transaction was not found | ||
result = tracetestcli.Exec(t, "delete transaction --id Qti5R3_VR", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 1) | ||
require.Contains(result.StdErr, "Resource transactions with ID Qti5R3_VR not found") | ||
} |
108 changes: 108 additions & 0 deletions
108
testing/cli-e2etest/testscenarios/transaction/get_transaction_test.go
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,108 @@ | ||
package transaction | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/kubeshop/tracetest/cli-e2etest/environment" | ||
"github.com/kubeshop/tracetest/cli-e2etest/helpers" | ||
"github.com/kubeshop/tracetest/cli-e2etest/testscenarios/types" | ||
"github.com/kubeshop/tracetest/cli-e2etest/tracetestcli" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func addGetTransactionPreReqs(t *testing.T, env environment.Manager) { | ||
cliConfig := env.GetCLIConfigPath(t) | ||
|
||
// Given I am a Tracetest CLI user | ||
// And I have my server recently created | ||
|
||
// When I try to set up a new transaction | ||
// Then it should be applied with success | ||
newTransactionPath := env.GetTestResourcePath(t, "new-transaction") | ||
|
||
result := tracetestcli.Exec(t, fmt.Sprintf("apply transaction --file %s", newTransactionPath), tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
} | ||
|
||
func TestGetTransaction(t *testing.T) { | ||
// instantiate require with testing helper | ||
require := require.New(t) | ||
|
||
env := environment.CreateAndStart(t) | ||
defer env.Close(t) | ||
|
||
cliConfig := env.GetCLIConfigPath(t) | ||
|
||
t.Run("get with no transaction initialized", func(t *testing.T) { | ||
// Given I am a Tracetest CLI user | ||
// And I have my server recently created | ||
// And no transaction registered | ||
|
||
// When I try to get a transaction on yaml mode | ||
// Then it should return a error message | ||
result := tracetestcli.Exec(t, "get transaction --id no-id --output yaml", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
require.Contains(result.StdOut, "Resource transaction with ID no-id not found") | ||
}) | ||
|
||
addGetTransactionPreReqs(t, env) | ||
|
||
t.Run("get with YAML format", func(t *testing.T) { | ||
// Given I am a Tracetest CLI user | ||
// And I have my server recently created | ||
// And I have a transaction already set | ||
|
||
// When I try to get a transaction on yaml mode | ||
// Then it should print a YAML | ||
result := tracetestcli.Exec(t, "get transaction --id Qti5R3_VR --output yaml", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
|
||
transaction := helpers.UnmarshalYAML[types.TransactionResource](t, result.StdOut) | ||
|
||
require.Equal("Transaction", transaction.Type) | ||
require.Equal("Qti5R3_VR", transaction.Spec.ID) | ||
require.Equal("New Transaction", transaction.Spec.Name) | ||
require.Equal("a transaction", transaction.Spec.Description) | ||
require.Len(transaction.Spec.Steps, 2) | ||
require.Equal("9wtAH2_Vg", transaction.Spec.Steps[0]) | ||
require.Equal("ajksdkasjbd", transaction.Spec.Steps[1]) | ||
}) | ||
|
||
t.Run("get with JSON format", func(t *testing.T) { | ||
// Given I am a Tracetest CLI user | ||
// And I have my server recently created | ||
// And I have a transaction already set | ||
|
||
// When I try to get a transaction on json mode | ||
// Then it should print a json | ||
result := tracetestcli.Exec(t, "get transaction --id Qti5R3_VR --output json", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
|
||
transaction := helpers.UnmarshalJSON[types.TransactionResource](t, result.StdOut) | ||
|
||
require.Equal("Transaction", transaction.Type) | ||
require.Equal("Qti5R3_VR", transaction.Spec.ID) | ||
require.Equal("New Transaction", transaction.Spec.Name) | ||
require.Equal("a transaction", transaction.Spec.Description) | ||
require.Len(transaction.Spec.Steps, 2) | ||
require.Equal("9wtAH2_Vg", transaction.Spec.Steps[0]) | ||
require.Equal("ajksdkasjbd", transaction.Spec.Steps[1]) | ||
}) | ||
|
||
t.Run("get with pretty format", func(t *testing.T) { | ||
// Given I am a Tracetest CLI user | ||
// And I have my server recently created | ||
// And I have a transaction already set | ||
|
||
// When I try to get a transaction on pretty mode | ||
// Then it should print a table with 4 lines printed: header, separator, transaction item and empty line | ||
result := tracetestcli.Exec(t, "get transaction --id Qti5R3_VR --output pretty", tracetestcli.WithCLIConfig(cliConfig)) | ||
helpers.RequireExitCodeEqual(t, result, 0) | ||
require.Contains(result.StdOut, "New Transaction") | ||
|
||
lines := strings.Split(result.StdOut, "\n") | ||
require.Len(lines, 4) | ||
}) | ||
} |
Oops, something went wrong.