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

dummy #24

Closed
wants to merge 5 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
12 changes: 12 additions & 0 deletions cli/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func setupOutputFormat(cmd *cobra.Command) {
}

func loadConfig(cmd *cobra.Command, args []string) {
fmt.Println("Loading configuration...") // Debug line

config, err := config.LoadConfig(configFile)
if err != nil {
cliLogger.Fatal("could not load config", zap.Error(err))
Expand All @@ -112,13 +114,17 @@ func loadConfig(cmd *cobra.Command, args []string) {
}

func validateConfig(cmd *cobra.Command, args []string) {
fmt.Println("Validating configuration...") // Debug line

if cliConfig.IsEmpty() {
cliLogger.Warn("You haven't configured your CLI, some commands might fail!")
cliLogger.Warn("Run 'qt configure' to configure your CLI")
}
}

func setupLogger(cmd *cobra.Command, args []string) {
fmt.Println("Setting up logger...") // Debug line

atom := zap.NewAtomicLevel()
if verbose {
atom.SetLevel(zap.DebugLevel)
Expand Down Expand Up @@ -150,10 +156,14 @@ func setupLogger(cmd *cobra.Command, args []string) {
}

func teardownCommand(cmd *cobra.Command, args []string) {
fmt.Println("Tearing down command...") // Debug line

cliLogger.Sync()
}

func setupVersion() {
fmt.Println("Setting up version...") // Debug line

versionText, isVersionMatch = actions.GetVersion(
context.Background(),
cliConfig,
Expand All @@ -162,6 +172,8 @@ func setupVersion() {
}

func validateVersionMismatch() {
fmt.Println("Validating version mismatch...") // Debug line

if !isVersionMatch && os.Getenv("TRACETEST_DEV") == "" {
fmt.Fprintf(os.Stderr, versionText+`
✖️ Error: Version Mismatch
Expand Down
118 changes: 101 additions & 17 deletions cli/cmd/resource_apply_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"encoding/json"

"github.com/kubeshop/tracetest/cli/pkg/fileutil"
"github.com/kubeshop/tracetest/cli/pkg/resourcemanager"
Expand All @@ -25,6 +26,9 @@ func init() {
resourceType := resourceParams.ResourceName
ctx := context.Background()

// Debug: Print the value of the "gitrepo" flag
fmt.Println("Git Repo Flag:", applyParams.GitRepo)

resourceClient, err := resources.Get(resourceType)
if err != nil {
return "", err
Expand All @@ -34,39 +38,119 @@ func init() {
if err != nil {
return "", err
}

// Check if a definition file is provided
if applyParams.DefinitionFile != "" {
// If a file name is provided, read its contents
inputFile, err := fileutil.Read(applyParams.DefinitionFile)
if err != nil {
return "", fmt.Errorf("cannot read file %s: %w", applyParams.DefinitionFile, err)
}

inputFile, err := fileutil.Read(applyParams.DefinitionFile)
if err != nil {
return "", fmt.Errorf("cannot read file %s: %w", applyParams.DefinitionFile, err)
}
result, err := resourceClient.Apply(ctx, inputFile, resultFormat)
if err != nil {
return "", err
}

result, err := resourceClient.Apply(ctx, inputFile, resultFormat)
if err != nil {
return "", err
return result, nil
} else {
// If no file name is provided, use Git parameters as JSON body
// Construct the JSON body using Git parameters
gitParams := map[string]string{
"gitRepo": applyParams.GitRepo,
"gitUsername": applyParams.GitUsername,
"gitToken": applyParams.GitToken,
"repoName": applyParams.RepoName,
"branch": applyParams.Branch,
"gitFile": applyParams.GitFile,
}
// Convert the map to JSON
jsonBody, err := json.Marshal(gitParams)
if err != nil {
return "", fmt.Errorf("error creating JSON body: %w", err)
}

return string(jsonBody), nil
}

return result, nil
}, applyParams),
PostRun: teardownCommand,
}

applyCmd.Flags().StringVarP(&applyParams.DefinitionFile, "file", "f", "", "path to the definition file")
applyCmd.Flags().StringVarP(&applyParams.GitRepo, "gitrepo", "", "", "Git repository name")
applyCmd.Flags().StringVarP(&applyParams.GitUsername, "gitusername", "", "", "Git username")
applyCmd.Flags().StringVarP(&applyParams.GitToken, "gittoken", "", "", "Git token")
applyCmd.Flags().StringVarP(&applyParams.RepoName, "reponame", "", "", "Repository name")
applyCmd.Flags().StringVarP(&applyParams.Branch, "branch", "", "", "Branch name")
applyCmd.Flags().StringVarP(&applyParams.GitFile, "gitfile", "", "", "Git file name")

rootCmd.AddCommand(applyCmd)
}

type applyParameters struct {
DefinitionFile string
GitRepo string
GitUsername string
GitToken string
RepoName string
Branch string
GitFile string
}

func (p applyParameters) Validate(cmd *cobra.Command, args []string) []error {
errors := make([]error, 0)
errors := make([]error, 0)

if p.DefinitionFile == "" {
errors = append(errors, paramError{
Parameter: "file",
Message: "Definition file must be provided",
})
}
if p.DefinitionFile == "" {
gitErrors := p.validateGitParameters()
errors = append(errors, gitErrors...)
}

return errors
return errors
}

func (p applyParameters) validateGitParameters() []error {
gitErrors := make([]error, 0)

// Add specific validation checks for Git parameters
if p.GitRepo == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "git-repo",
Message: "Git repository is required",
})
}
if p.GitUsername == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "gitusername",
Message: "Git username is required",
})
}

if p.GitToken == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "gittoken",
Message: "Git token is required",
})
}

if p.RepoName == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "reponame",
Message: "Repository name is required",
})
}

if p.Branch == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "branch",
Message: "Branch name is required",
})
}

if p.GitFile == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "gitfile",
Message: "Git file name is required",
})
}
return gitErrors
}
154 changes: 119 additions & 35 deletions cli/cmd/resource_run_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@ func init() {
runParams.VarsID = runParams.EnvID
}

runParams := runner.RunOptions{
params := runner.RunOptions{
ID: runParams.ID,
DefinitionFile: runParams.DefinitionFile,
VarsID: runParams.VarsID,
SkipResultWait: runParams.SkipResultWait,
JUnitOuptutFile: runParams.JUnitOuptutFile,
RequiredGates: runParams.RequriedGates,
GitRepo: runParams.GitRepo,
GitUsername: runParams.GitUsername,
GitToken: runParams.GitToken,
RepoName: runParams.RepoName,
Branch: runParams.Branch,
GitFile: runParams.GitFile,
}

exitCode, err := orchestrator.Run(ctx, r, runParams, output)
exitCode, err := orchestrator.Run(ctx, r, params, output)
if err != nil {
return "", err
}
Expand All @@ -72,11 +78,18 @@ func init() {
runCmd.Flags().StringVarP(&runParams.JUnitOuptutFile, "junit", "j", "", "file path to save test results in junit format")
runCmd.Flags().StringSliceVar(&runParams.RequriedGates, "required-gates", []string{}, "override default required gate. "+validRequiredGatesMsg())

runCmd.Flags().StringVarP(&runParams.GitRepo, "gitrepo", "", "", "Git repository name")
runCmd.Flags().StringVarP(&runParams.GitUsername, "gitusername", "", "", "Git username")
runCmd.Flags().StringVarP(&runParams.GitToken, "gittoken", "", "", "Git token")
runCmd.Flags().StringVarP(&runParams.RepoName, "reponame", "", "", "Repository name")
runCmd.Flags().StringVarP(&runParams.Branch, "branch", "", "", "Branch name")
runCmd.Flags().StringVarP(&runParams.GitFile, "gitfile", "", "", "Git file name")

//deprecated
runCmd.Flags().StringVarP(&runParams.EnvID, "environment", "e", "", "environment file or ID to be used")
runCmd.Flags().MarkDeprecated("environment", "use --vars instead")
runCmd.Flags().MarkShorthandDeprecated("e", "use --vars instead")

rootCmd.AddCommand(runCmd)
}

Expand All @@ -97,40 +110,111 @@ type runParameters struct {
SkipResultWait bool
JUnitOuptutFile string
RequriedGates []string
GitRepo string
GitUsername string
GitToken string
RepoName string
Branch string
GitFile string
}

func (p runParameters) Validate(cmd *cobra.Command, args []string) []error {
errs := []error{}
if p.DefinitionFile == "" && p.ID == "" {
errs = append(errs, paramError{
Parameter: "resource",
Message: "you must specify a definition file or resource ID",
})
}

if p.DefinitionFile != "" && p.ID != "" {
errs = append(errs, paramError{
Parameter: "resource",
Message: "you cannot specify both a definition file and resource ID",
})
}

if p.JUnitOuptutFile != "" && p.SkipResultWait {
errs = append(errs, paramError{
Parameter: "junit",
Message: "--junit option is incompatible with --skip-result-wait option",
})
}

for _, rg := range p.RequriedGates {
_, err := openapi.NewSupportedGatesFromValue(rg)
if err != nil {
errs = append(errs, paramError{
Parameter: "required-gates",
Message: fmt.Sprintf("invalid option '%s'. "+validRequiredGatesMsg(), rg),
})
}
}

return errs
errs := []error{}
// Check for incompatibility between JUnit and SkipResultWait options
if p.JUnitOuptutFile != "" && p.SkipResultWait {
errs = append(errs, paramError{
Parameter: "junit",
Message: "--junit option is incompatible with --skip-result-wait option",
})
}

if p.GitRepo != "" || p.GitUsername != "" || p.GitToken != "" || p.RepoName != "" || p.Branch != "" || p.GitFile != "" {

// Print Git parameters for debugging
fmt.Println("Git Repo:", p.GitRepo)
fmt.Println("Git Username:", p.GitUsername)
fmt.Println("Git Token:", p.GitToken)
fmt.Println("Repo Name:", p.RepoName)
fmt.Println("Branch:", p.Branch)
fmt.Println("Git File:", p.GitFile)

// Call the validateGitParameters function
gitErrors := p.validateGitParameters()
errs = append(errs, gitErrors...)

} else if p.DefinitionFile == "" && p.ID == "" {
// Check for either DefinitionFile or ID
errs = append(errs, paramError{
Parameter: "resource",
Message: "you must specify a definition file or resource ID",
})

} else if p.DefinitionFile != "" && p.ID != "" {
errs = append(errs, paramError{
Parameter: "resource",
Message: "you cannot specify both a definition file and resource ID",
})
}


// Validate required gates
for _, rg := range p.RequriedGates {
_, err := openapi.NewSupportedGatesFromValue(rg)
if err != nil {
errs = append(errs, paramError{
Parameter: "required-gates",
Message: fmt.Sprintf("invalid option '%s'. "+validRequiredGatesMsg(), rg),
})
}
}

return errs
}

func (p runParameters) validateGitParameters() []error {
gitErrors := make([]error, 0)

// Add specific validation checks for Git parameters
if p.GitRepo == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "git-repo",
Message: "Git repository is required",
})
}
if p.GitUsername == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "gitusername",
Message: "Git username is required",
})
}

if p.GitToken == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "gittoken",
Message: "Git token is required",
})
}

if p.RepoName == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "reponame",
Message: "Repository name is required",
})
}

if p.Branch == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "branch",
Message: "Branch name is required",
})
}

if p.GitFile == "" {
gitErrors = append(gitErrors, paramError{
Parameter: "gitfile",
Message: "Git file name is required",
})
}
return gitErrors
}
Loading
Loading