diff --git a/cmd/kubectl-testkube/commands/tests/executions.go b/cmd/kubectl-testkube/commands/tests/executions.go index 373e6b9a9be..432aff0156b 100644 --- a/cmd/kubectl-testkube/commands/tests/executions.go +++ b/cmd/kubectl-testkube/commands/tests/executions.go @@ -10,24 +10,26 @@ import ( func NewTestExecutionsCmd() *cobra.Command { var ( - name string limit int tags []string ) cmd := &cobra.Command{ - Use: "executions", + Use: "executions [testName]", Aliases: []string{"el"}, Short: "Gets tests executions list", Long: `Gets tests executions list, can be filtered by test name`, Run: func(cmd *cobra.Command, args []string) { ui.Logo() - testName := args[0] + var testName string + if len(args) > 0 { + testName = args[0] + } client, _ := common.GetClient(cmd) - executions, err := client.ListTestExecutions(testName, 1000, tags) + executions, err := client.ListTestExecutions(testName, limit, tags) ui.ExitOnError("getting tests executions list", err) ui.Table(executions, os.Stdout) @@ -37,7 +39,6 @@ func NewTestExecutionsCmd() *cobra.Command { } cmd.Flags().IntVar(&limit, "limit", 1000, "execution name, if empty will be autogenerated") - cmd.Flags().StringVarP(&name, "name", "n", "", "execution name, if empty will be autogenerated") cmd.Flags().StringSliceVar(&tags, "tags", nil, "comma separated list of tags: --tags tag1,tag2,tag3") return cmd diff --git a/go.sum b/go.sum index bc2d352ed21..8792b001604 100644 --- a/go.sum +++ b/go.sum @@ -368,8 +368,6 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubeshop/testkube-operator v0.7.5 h1:txf0QRc0R7EUb6clcvta4GEgcnp4QQzYCm4M8BRuR5k= -github.com/kubeshop/testkube-operator v0.7.5/go.mod h1:P1LXcaJEt1eVVrdRlDZip9mNHEP7cN64USQ6u/aCOeo= github.com/kubeshop/testkube-operator v0.9.1 h1:rWMHuVYOJ/oItoBABG1b8vhx+kridO36JRm+8p17Lfc= github.com/kubeshop/testkube-operator v0.9.1/go.mod h1:P1LXcaJEt1eVVrdRlDZip9mNHEP7cN64USQ6u/aCOeo= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= diff --git a/internal/app/api/v1/tests.go b/internal/app/api/v1/tests.go index 6d9fd52d8fa..a45ed532c87 100644 --- a/internal/app/api/v1/tests.go +++ b/internal/app/api/v1/tests.go @@ -296,9 +296,9 @@ func newTestStepExecutionResult(execution testkube.Execution, step *testkube.Tes func getExecutionsFilterFromRequest(c *fiber.Ctx) testresult.Filter { filter := testresult.NewExecutionsFilter() - scriptName := c.Params("id", "") - if scriptName != "" { - filter = filter.WithScriptName(scriptName) + name := c.Query("id", "") + if name != "" { + filter = filter.WithName(name) } textSearch := c.Query("textSearch", "") diff --git a/internal/pkg/api/repository/testresult/filter.go b/internal/pkg/api/repository/testresult/filter.go index c02d90ddeb7..75c0b2ea015 100644 --- a/internal/pkg/api/repository/testresult/filter.go +++ b/internal/pkg/api/repository/testresult/filter.go @@ -7,7 +7,7 @@ import ( ) type filter struct { - scriptName string + name string startDate *time.Time endDate *time.Time status *testkube.ExecutionStatus @@ -21,8 +21,8 @@ func NewExecutionsFilter() *filter { return &result } -func (f *filter) WithScriptName(scriptName string) *filter { - f.scriptName = scriptName +func (f *filter) WithName(name string) *filter { + f.name = name return f } @@ -57,11 +57,11 @@ func (f *filter) WithTextSearch(textSearch string) *filter { } func (f filter) Name() string { - return f.scriptName + return f.name } func (f filter) NameDefined() bool { - return f.scriptName != "" + return f.name != "" } func (f filter) StartDateDefined() bool { diff --git a/internal/pkg/api/repository/testresult/mongo.go b/internal/pkg/api/repository/testresult/mongo.go index fad80fe40bc..9c4d6766435 100644 --- a/internal/pkg/api/repository/testresult/mongo.go +++ b/internal/pkg/api/repository/testresult/mongo.go @@ -127,6 +127,10 @@ func composeQueryAndOpts(filter Filter) (bson.M, *options.FindOptions) { opts := options.Find() startTimeQuery := bson.M{} + if filter.NameDefined() { + query["test.name"] = filter.Name() + } + if filter.TextSearchDefined() { query["name"] = bson.M{"$regex": primitive.Regex{Pattern: filter.TextSearch(), Options: "i"}} }