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

fix: test execution filters by name #824

Merged
merged 1 commit into from
Jan 21, 2022
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
11 changes: 6 additions & 5 deletions cmd/kubectl-testkube/commands/tests/executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions internal/app/api/v1/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/api/repository/testresult/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type filter struct {
scriptName string
name string
startDate *time.Time
endDate *time.Time
status *testkube.ExecutionStatus
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/api/repository/testresult/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}
}
Expand Down