github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/test/e2e/testdata/smoketest/analyze_report.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package smoketest 21 22 import ( 23 "fmt" 24 "log" 25 "os" 26 27 . "github.com/onsi/ginkgo/v2" 28 29 . "github.com/1aal/kubeblocks/test/e2e" 30 e2eutil "github.com/1aal/kubeblocks/test/e2e/util" 31 ) 32 33 func AnalyzeE2eReport() { 34 35 BeforeEach(func() { 36 }) 37 38 AfterEach(func() { 39 }) 40 41 Context("show e2e test report", func() { 42 dir, err := os.Getwd() 43 if err != nil { 44 log.Println(err) 45 } 46 It("create e2e report file", func() { 47 f, err := os.OpenFile(TestType+"-log.txt", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) 48 if err != nil { 49 fmt.Println("Failed to open file:", err) 50 return 51 } 52 log.SetOutput(f) 53 }) 54 It("e2e report", func() { 55 log.Println("\n====================" + TestType + " e2e test report====================") 56 if len(TestResults) > 0 && len(TestType) > 0 { 57 files, _ := e2eutil.GetFiles(dir + "/testdata/smoketest/" + TestType) 58 if len(files) > len(TestResults) { 59 failed := len(files) - len(TestResults) 60 log.Println("Total " + fmt.Sprint(len(files)) + " | " + "Passed " + 61 fmt.Sprint(len(TestResults)) + " | " + "Failed " + fmt.Sprint(failed)) 62 } else { 63 log.Println("Total " + fmt.Sprint(len(TestResults)) + " | " + "Passed " + fmt.Sprint(len(TestResults))) 64 } 65 var CaseNames []string 66 for _, v := range TestResults { 67 CaseNames = append(CaseNames, v.CaseName) 68 if v.ExecuteResult { 69 log.Printf(" [PASS] [%s] %s %s ", v.CaseName, fmt.Sprint(v.ExecuteResult), v.TroubleShooting) 70 } else { 71 log.Printf(" [ERROR] [%s] %s %s ", v.CaseName, fmt.Sprint(v.ExecuteResult), v.TroubleShooting) 72 } 73 } 74 if len(files) > len(TestResults) { 75 var filesNames []string 76 for _, file := range files { 77 name := e2eutil.GetPrefix(file, "/") 78 filesNames = append(filesNames, name) 79 } 80 diffs := e2eutil.RemoveElements(filesNames, CaseNames) 81 for _, diff := range diffs { 82 log.Printf(" [ERROR] [%s] %s %s ", diff, fmt.Sprint(false), "") 83 } 84 } 85 } 86 if len(TestResults) == 0 { 87 log.Println("[ERROR] create cluster failed") 88 } 89 }) 90 }) 91 }