-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: list test workflow execution tags Signed-off-by: Vladislav Sukhin <[email protected]> * feat: add tags model Signed-off-by: Vladislav Sukhin <[email protected]> * fix: convert dots Signed-off-by: Vladislav Sukhin <[email protected]> * fix: rename error prefix Signed-off-by: Vladislav Sukhin <[email protected]> * fix: add execution tags command Signed-off-by: Vladislav Sukhin <[email protected]> --------- Signed-off-by: Vladislav Sukhin <[email protected]>
- Loading branch information
Showing
12 changed files
with
208 additions
and
40 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func (s TestkubeAPI) ListLabelsHandler() fiber.Handler { | ||
return func(c *fiber.Ctx) error { | ||
labels := make(map[string][]string) | ||
sources := append(*s.LabelSources, s.TestsClient, s.TestsSuitesClient) | ||
|
||
for _, source := range sources { | ||
nextLabels, err := source.ListLabels() | ||
if err != nil { | ||
return s.Error(c, http.StatusBadGateway, fmt.Errorf("failed to list labels: %w", err)) | ||
} | ||
|
||
deduplicateMap(nextLabels, labels) | ||
} | ||
|
||
return c.JSON(labels) | ||
} | ||
} | ||
|
||
func (s *TestkubeAPI) ListTagsHandler() fiber.Handler { | ||
return func(c *fiber.Ctx) error { | ||
errPrefix := "failed to list execution tags" | ||
|
||
tags, err := s.TestWorkflowResults.GetExecutionTags(c.Context()) | ||
if err != nil { | ||
return s.ClientError(c, errPrefix, err) | ||
} | ||
|
||
results := make(map[string][]string) | ||
deduplicateMap(tags, results) | ||
|
||
return c.JSON(results) | ||
} | ||
} | ||
|
||
func deduplicateMap(src, dst map[string][]string) { | ||
for key, testValues := range src { | ||
valuesMap := make(map[string]struct{}) | ||
if values, ok := dst[key]; ok { | ||
for _, v := range values { | ||
valuesMap[v] = struct{}{} | ||
} | ||
} | ||
|
||
for _, testValue := range testValues { | ||
if _, ok := valuesMap[testValue]; !ok { | ||
dst[key] = append(dst[key], testValue) | ||
valuesMap[testValue] = struct{}{} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Testkube API | ||
* | ||
* Testkube provides a Kubernetes-native framework for test definition, execution and results | ||
* | ||
* API version: 1.0.0 | ||
* Contact: [email protected] | ||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) | ||
*/ | ||
package testkube | ||
|
||
type TestWorkflowExecutionTags struct { | ||
Tags map[string]string `json:"tags,omitempty"` | ||
} |
18 changes: 18 additions & 0 deletions
18
pkg/api/v1/testkube/model_test_workflow_execution_tags_extended.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,18 @@ | ||
package testkube | ||
|
||
import "github.com/kubeshop/testkube/pkg/utils" | ||
|
||
func (t *TestWorkflowExecutionTags) ConvertDots(fn func(string) string) *TestWorkflowExecutionTags { | ||
if t.Tags != nil { | ||
t.Tags = convertDotsInMap(t.Tags, fn) | ||
} | ||
return t | ||
} | ||
|
||
func (t *TestWorkflowExecutionTags) EscapeDots() *TestWorkflowExecutionTags { | ||
return t.ConvertDots(utils.EscapeDots) | ||
} | ||
|
||
func (t *TestWorkflowExecutionTags) UnscapeDots() *TestWorkflowExecutionTags { | ||
return t.ConvertDots(utils.UnescapeDots) | ||
} |
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
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
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