Skip to content

Commit

Permalink
fix: script contenttype detect when creating script
Browse files Browse the repository at this point in the history
  • Loading branch information
exu committed Feb 4, 2022
1 parent 5dfc3c8 commit 4388d37
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
18 changes: 16 additions & 2 deletions cmd/kubectl-testkube/commands/scripts/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func watchLogs(id string, client apiclientv1.Client) {
func newContentFromFlags(cmd *cobra.Command) (content *testkube.ScriptContent, err error) {
var fileContent []byte

scriptContentType := cmd.Flag("script-content-type").Value.String()
file := cmd.Flag("file").Value.String()
uri := cmd.Flag("uri").Value.String()
gitUri := cmd.Flag("git-uri").Value.String()
Expand All @@ -112,12 +113,16 @@ func newContentFromFlags(cmd *cobra.Command) (content *testkube.ScriptContent, e
}
}

if len(fileContent) == 0 && len(uri) == 0 {
// content is correct when is passed from file, by uri, ur by git repo
if len(fileContent) == 0 && (uri == "" || gitUri == "") {
return content, fmt.Errorf("empty script content, please pass some script content to create script")
}

var repository *testkube.Repository
if uri != "" && gitBranch != "" {
if gitUri != "" && gitBranch != "" {
if scriptContentType == "" {
scriptContentType = "git-dir"
}
repository = &testkube.Repository{
Type_: "git",
Uri: gitUri,
Expand All @@ -128,7 +133,16 @@ func newContentFromFlags(cmd *cobra.Command) (content *testkube.ScriptContent, e
}
}

if uri != "" {
scriptContentType = "uri"
}

if scriptContentType == "" {
scriptContentType = "string"
}

content = &testkube.ScriptContent{
Type_: scriptContentType,
Data: string(fileContent),
Repository: repository,
Uri: uri,
Expand Down
24 changes: 13 additions & 11 deletions cmd/kubectl-testkube/commands/scripts/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import (
func NewCreateScriptsCmd() *cobra.Command {

var (
scriptName string
scriptNamespace string
file string
executorType string
uri string
gitUri string
gitBranch string
gitPath string
gitUsername string
gitToken string
tags []string
scriptName string
scriptNamespace string
scriptContentType string
file string
executorType string
uri string
gitUri string
gitBranch string
gitPath string
gitUsername string
gitToken string
tags []string
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -50,6 +51,7 @@ func NewCreateScriptsCmd() *cobra.Command {
cmd.Flags().StringVarP(&scriptName, "name", "n", "", "unique script name - mandatory")
cmd.Flags().StringVarP(&file, "file", "f", "", "script file - will be read from stdin if not specified")
cmd.Flags().StringVarP(&scriptNamespace, "script-namespace", "", "testkube", "namespace where script will be created defaults to 'testkube' namespace")
cmd.Flags().StringVarP(&scriptContentType, "script-content-type", "", "", "content type of script one of string|file-uri|git-file|git-dir")

cmd.Flags().StringVarP(&executorType, "type", "t", "", "script type (defaults to postman-collection)")

Expand Down
26 changes: 15 additions & 11 deletions cmd/kubectl-testkube/commands/scripts/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import (
func NewUpdateScriptsCmd() *cobra.Command {

var (
scriptName string
scriptNamespace string
file string
executorType string
uri string
gitUri string
gitBranch string
gitPath string
gitUsername string
gitToken string
tags []string
scriptName string
scriptNamespace string
scriptContentType string
file string
executorType string
uri string
gitUri string
gitBranch string
gitPath string
gitUsername string
gitToken string
tags []string
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -49,7 +50,10 @@ func NewUpdateScriptsCmd() *cobra.Command {
cmd.Flags().StringVarP(&scriptName, "name", "n", "", "unique script name - mandatory")
cmd.Flags().StringVarP(&file, "file", "f", "", "script file - will try to read content from stdin if not specified")
cmd.Flags().StringVarP(&scriptNamespace, "script-namespace", "", "testkube", "namespace where script will be created defaults to 'testkube' namespace")
cmd.Flags().StringVarP(&scriptContentType, "script-content-type", "", "", "content type of script one of string|file-uri|git-file|git-dir")

cmd.Flags().StringVarP(&executorType, "type", "t", "", "script type (defaults to postman-collection)")

cmd.Flags().StringVarP(&uri, "uri", "", "", "URI of resource - will be loaded by http GET")
cmd.Flags().StringVarP(&gitUri, "git-uri", "", "", "Git repository uri")
cmd.Flags().StringVarP(&gitBranch, "git-branch", "", "", "if uri is git repository we can set additional branch parameter")
Expand Down

0 comments on commit 4388d37

Please sign in to comment.