github.com/kubeshop/testkube@v1.17.23/pkg/tcl/testworkflowstcl/testworkflowresolver/analyze.go (about) 1 // Copyright 2024 Testkube. 2 // 3 // Licensed as a Testkube Pro file under the Testkube Community 4 // License (the "License"); you may not use this file except in compliance with 5 // the License. You may obtain a copy of the License at 6 // 7 // https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt 8 9 package testworkflowresolver 10 11 import ( 12 "maps" 13 "strings" 14 15 testworkflowsv1 "github.com/kubeshop/testkube-operator/api/testworkflows/v1" 16 ) 17 18 func GetInternalTemplateName(name string) string { 19 return strings.ReplaceAll(name, "/", "--") 20 } 21 22 func GetDisplayTemplateName(name string) string { 23 return strings.ReplaceAll(name, "--", "/") 24 } 25 26 func listStepTemplates(cr testworkflowsv1.Step) map[string]struct{} { 27 v := make(map[string]struct{}) 28 if cr.Template != nil { 29 v[GetInternalTemplateName(cr.Template.Name)] = struct{}{} 30 } 31 for i := range cr.Use { 32 v[GetInternalTemplateName(cr.Use[i].Name)] = struct{}{} 33 } 34 for i := range cr.Setup { 35 maps.Copy(v, listStepTemplates(cr.Setup[i])) 36 } 37 for i := range cr.Steps { 38 maps.Copy(v, listStepTemplates(cr.Steps[i])) 39 } 40 return v 41 } 42 43 func ListTemplates(cr *testworkflowsv1.TestWorkflow) map[string]struct{} { 44 if cr == nil { 45 return nil 46 } 47 v := make(map[string]struct{}) 48 for i := range cr.Spec.Use { 49 v[GetInternalTemplateName(cr.Spec.Use[i].Name)] = struct{}{} 50 } 51 for i := range cr.Spec.Setup { 52 maps.Copy(v, listStepTemplates(cr.Spec.Setup[i])) 53 } 54 for i := range cr.Spec.Steps { 55 maps.Copy(v, listStepTemplates(cr.Spec.Steps[i])) 56 } 57 for i := range cr.Spec.After { 58 maps.Copy(v, listStepTemplates(cr.Spec.After[i])) 59 } 60 return v 61 }