github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/tests/update.go (about) 1 package tests 2 3 import ( 4 "github.com/spf13/cobra" 5 6 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" 7 "github.com/kubeshop/testkube/pkg/ui" 8 ) 9 10 func NewUpdateTestsCmd() *cobra.Command { 11 12 var ( 13 testName string 14 testContentType string 15 file string 16 uri string 17 gitUri string 18 gitBranch string 19 gitCommit string 20 gitPath string 21 gitUsername string 22 gitToken string 23 sourceName string 24 gitUsernameSecret map[string]string 25 gitTokenSecret map[string]string 26 gitWorkingDir string 27 gitCertificateSecret string 28 gitAuthType string 29 ) 30 31 cmd := &cobra.Command{ 32 Use: "test", 33 Short: "Update test", 34 Long: `Update Test Custom Resource`, 35 Run: func(cmd *cobra.Command, args []string) { 36 var err error 37 38 if testName == "" { 39 ui.Failf("pass valid test name (in '--name' flag)") 40 } 41 42 client, namespace, err := common.GetClient(cmd) 43 ui.ExitOnError("getting client", err) 44 45 test, _ := client.GetTest(testName) 46 if testName != test.Name { 47 ui.Failf("Test with name '%s' not exists in namespace %s", testName, namespace) 48 } 49 50 options, err := NewUpdateTestOptionsFromFlags(cmd) 51 ui.ExitOnError("getting test options", err) 52 53 test, err = client.UpdateTest(options) 54 ui.ExitOnError("updating test "+testName+" in namespace "+namespace, err) 55 56 ui.Success("Test updated", namespace, "/", testName) 57 }, 58 } 59 60 cmd.Flags().StringVarP(&testName, "name", "n", "", "unique test name - mandatory") 61 cmd.Flags().StringVarP(&file, "file", "f", "", "test file - will try to read content from stdin if not specified") 62 cmd.Flags().StringVarP(&testContentType, "test-content-type", "", "", "content type of test one of string|file-uri|git") 63 cmd.Flags().StringVarP(&uri, "uri", "", "", "URI of resource - will be loaded by http GET") 64 cmd.Flags().StringVarP(&gitUri, "git-uri", "", "", "Git repository uri") 65 cmd.Flags().StringVarP(&gitBranch, "git-branch", "", "", "if uri is git repository we can set additional branch parameter") 66 cmd.Flags().StringVarP(&gitCommit, "git-commit", "", "", "if uri is git repository we can use commit id (sha) parameter") 67 cmd.Flags().StringVarP(&gitPath, "git-path", "", "", "if repository is big we need to define additional path to directory/file to checkout partially") 68 cmd.Flags().StringVarP(&gitWorkingDir, "git-working-dir", "", "", "if repository contains multiple directories with tests (like monorepo) and one starting directory we can set working directory parameter") 69 cmd.Flags().StringVarP(&gitUsername, "git-username", "", "", "if git repository is private we can use username as an auth parameter") 70 cmd.Flags().StringVarP(&gitToken, "git-token", "", "", "if git repository is private we can use token as an auth parameter") 71 cmd.Flags().StringToStringVarP(&gitUsernameSecret, "git-username-secret", "", map[string]string{}, "git username secret in a form of secret_name1=secret_key1 for private repository") 72 cmd.Flags().StringToStringVarP(&gitTokenSecret, "git-token-secret", "", map[string]string{}, "git token secret in a form of secret_name1=secret_key1 for private repository") 73 cmd.Flags().StringVarP(&gitCertificateSecret, "git-certificate-secret", "", "", "if git repository is private we can use certificate as an auth parameter stored in a kubernetes secret name") 74 cmd.Flags().StringVarP(&gitAuthType, "git-auth-type", "", "basic", "auth type for git requests one of basic|header") 75 cmd.Flags().StringVarP(&sourceName, "source", "", "", "source name - will be used together with content parameters") 76 cmd.Flags().MarkDeprecated("env", "env is deprecated use variable instead") 77 cmd.Flags().MarkDeprecated("secret-env", "secret-env is deprecated use secret-variable instead") 78 79 AddCreateFlags(cmd, &CreateCommonFlags{}) 80 81 return cmd 82 }