github.com/kubeshop/testkube@v1.17.23/pkg/api/v1/testkube/model_test_suite_base_extended.go (about) 1 package testkube 2 3 import ( 4 "fmt" 5 6 "github.com/kubeshop/testkube/pkg/data/set" 7 ) 8 9 type TestSuites []TestSuite 10 11 func (tests TestSuites) Table() (header []string, output [][]string) { 12 header = []string{"Name", "Description", "Steps", "Labels", "Schedule"} 13 for _, e := range tests { 14 output = append(output, []string{ 15 e.Name, 16 e.Description, 17 fmt.Sprintf("%d", len(e.Steps)), 18 MapToString(e.Labels), 19 e.Schedule, 20 }) 21 } 22 23 return 24 } 25 26 func (t TestSuite) GetObjectRef() *ObjectRef { 27 return &ObjectRef{ 28 Name: t.Name, 29 Namespace: t.Namespace, 30 } 31 } 32 33 // GetTestNames return test names for TestSuite 34 func (t TestSuite) GetTestNames() []string { 35 var names []string 36 var batches []TestSuiteBatchStep 37 38 batches = append(batches, t.Before...) 39 batches = append(batches, t.Steps...) 40 batches = append(batches, t.After...) 41 for _, batch := range batches { 42 for _, step := range batch.Execute { 43 if step.Test != "" { 44 names = append(names, step.Test) 45 } 46 } 47 } 48 49 return set.Of(names...).ToArray() 50 } 51 52 func (t *TestSuite) QuoteTestSuiteTextFields() { 53 if t.Description != "" { 54 t.Description = fmt.Sprintf("%q", t.Description) 55 } 56 57 if t.Schedule != "" { 58 t.Schedule = fmt.Sprintf("%q", t.Schedule) 59 } 60 61 if t.ExecutionRequest != nil { 62 for key, value := range t.ExecutionRequest.Variables { 63 if value.Value != "" { 64 value.Value = fmt.Sprintf("%q", value.Value) 65 t.ExecutionRequest.Variables[key] = value 66 } 67 } 68 69 var fields = []*string{ 70 &t.ExecutionRequest.JobTemplate, 71 &t.ExecutionRequest.CronJobTemplate, 72 &t.ExecutionRequest.PvcTemplate, 73 &t.ExecutionRequest.ScraperTemplate, 74 } 75 76 for _, field := range fields { 77 if *field != "" { 78 *field = fmt.Sprintf("%q", *field) 79 } 80 } 81 } 82 for i := range t.Before { 83 for j := range t.Before[i].Execute { 84 if t.Before[i].Execute[j].ExecutionRequest != nil { 85 t.Before[i].Execute[j].ExecutionRequest.QuoteTestSuiteStepExecutionRequestTextFields() 86 } 87 } 88 } 89 for i := range t.After { 90 for j := range t.After[i].Execute { 91 if t.After[i].Execute[j].ExecutionRequest != nil { 92 t.After[i].Execute[j].ExecutionRequest.QuoteTestSuiteStepExecutionRequestTextFields() 93 } 94 } 95 } 96 for i := range t.Steps { 97 for j := range t.Steps[i].Execute { 98 if t.Steps[i].Execute[j].ExecutionRequest != nil { 99 t.Steps[i].Execute[j].ExecutionRequest.QuoteTestSuiteStepExecutionRequestTextFields() 100 } 101 } 102 } 103 } 104 105 func (request *TestSuiteStepExecutionRequest) QuoteTestSuiteStepExecutionRequestTextFields() { 106 for i := range request.Args { 107 if request.Args[i] != "" { 108 request.Args[i] = fmt.Sprintf("%q", request.Args[i]) 109 } 110 } 111 112 for i := range request.Command { 113 if request.Command[i] != "" { 114 request.Command[i] = fmt.Sprintf("%q", request.Command[i]) 115 } 116 } 117 118 var fields = []*string{ 119 &request.JobTemplate, 120 &request.CronJobTemplate, 121 &request.ScraperTemplate, 122 &request.PvcTemplate, 123 } 124 125 for _, field := range fields { 126 if *field != "" { 127 *field = fmt.Sprintf("%q", *field) 128 } 129 } 130 }