github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/pkg/logs/log_naming.go (about) 1 package logs 2 3 import ( 4 "crypto/sha1" 5 "encoding/hex" 6 "strings" 7 8 types "github.com/onsi/ginkgo/v2/types" 9 ) 10 11 func GetClassnameFromReport(report types.SpecReport) string { 12 texts := []string{} 13 texts = append(texts, report.ContainerHierarchyTexts...) 14 if report.LeafNodeText != "" { 15 texts = append(texts, report.LeafNodeText) 16 } 17 if len(texts) > 0 { 18 classStrings := strings.Fields(texts[0]) 19 return classStrings[0][1:] 20 } else { 21 return strings.Join(texts, " ") 22 } 23 } 24 25 // This function is used to shorten classname and add hash to prevent issues with filesystems(255 chars for folder name) and to avoid conflicts(same shortened name of a classname) 26 func ShortenStringAddHash(report types.SpecReport) string { 27 className := GetClassnameFromReport(report) 28 s := report.FullText() 29 replacedClass := strings.Replace(s, className, "", 1) 30 if len(replacedClass) > 100 { 31 stringToHash := replacedClass[100:] 32 h := sha1.New() 33 h.Write([]byte(stringToHash)) 34 sha1_hash := hex.EncodeToString(h.Sum(nil)) 35 stringWithHash := replacedClass[0:100] + " sha: " + sha1_hash 36 return stringWithHash 37 } else { 38 return replacedClass 39 } 40 }