-
Notifications
You must be signed in to change notification settings - Fork 243
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
Save test results for each test spec to improve test results reporting #5449
Changes from 28 commits
e6e6254
afbd934
05afd87
4a12966
0e590e7
2b5a36a
ce9058d
7a75a2f
68f84ef
8895ca9
f205870
74a9afe
f440708
717a95f
d519894
64b56e7
6287935
6d2952f
7b0d393
b8ab487
9cb1ca6
858ca5d
260ad6c
24bb502
f57bdaf
fe85ae5
f17a19d
83650b1
2225212
a9431f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,6 +285,11 @@ type CommonVar struct { | |
// original values to get restored after the test is done | ||
OriginalWorkingDirectory string | ||
OriginalKubeconfig string | ||
// Ginkgo test realted | ||
testFileName string | ||
testCase string | ||
testFailed bool | ||
testDuration float64 | ||
} | ||
|
||
// CommonBeforeEach is common function runs before every test Spec (It) | ||
|
@@ -312,12 +317,47 @@ func CommonBeforeEach() CommonVar { | |
|
||
// CommonAfterEach is common function that cleans up after every test Spec (It) | ||
func CommonAfterEach(commonVar CommonVar) { | ||
// Get details, including test result for each test spec and adds it to local testResults.txt file | ||
// Ginkgo test related variables. | ||
commonVar.testFileName = strings.Replace(CurrentGinkgoTestDescription().FileName[strings.LastIndex(CurrentGinkgoTestDescription().FileName, "/")+1:strings.LastIndex(CurrentGinkgoTestDescription().FileName, ".")], "_", "-", -1) + ".go" | ||
commonVar.testCase = CurrentGinkgoTestDescription().FullTestText | ||
commonVar.testFailed = CurrentGinkgoTestDescription().Failed | ||
commonVar.testDuration = CurrentGinkgoTestDescription().Duration.Seconds() | ||
|
||
var prNum string | ||
var resultsRow string | ||
prNum = os.Getenv("GIT_PR_NUMBER") | ||
passedOrFailed := "PASSED" | ||
if commonVar.testFailed { | ||
passedOrFailed = "FAILED" | ||
} | ||
clusterType := "OCP" | ||
if IsKubernetesCluster() { | ||
clusterType = "KUBERNETES" | ||
} | ||
testDate := strings.Split(time.Now().Format(time.RFC3339), "T")[0] | ||
resultsRow = prNum + "," + testDate + "," + clusterType + "," + commonVar.testFileName + "," + commonVar.testCase + "," + passedOrFailed + "," + strconv.FormatFloat(commonVar.testDuration, 'E', -1, 64) + "\n" | ||
testResultsFile := filepath.Join("/", "tmp", "testResults.txt") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are we doing with this file? I assume this is not uploaded on any cloud storage bucket. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet, once this PR gets merged I will update the pipeline script to upload it to a bucket |
||
|
||
f, err := os.OpenFile(testResultsFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) | ||
if err != nil { | ||
fmt.Println("Error when opening file: ", err) | ||
} else { | ||
_, err = f.WriteString(resultsRow) | ||
if err != nil { | ||
fmt.Println("Error when writing to file: ", err) | ||
} | ||
if err = f.Close(); err != nil { | ||
fmt.Println("Error when closing file: ", err) | ||
} | ||
} | ||
|
||
// delete the random project/namespace created in CommonBeforeEach | ||
commonVar.CliRunner.DeleteNamespaceProject(commonVar.Project) | ||
|
||
// restores the original kubeconfig and working directory | ||
Chdir(commonVar.OriginalWorkingDirectory) | ||
err := os.Setenv("KUBECONFIG", commonVar.OriginalKubeconfig) | ||
err = os.Setenv("KUBECONFIG", commonVar.OriginalKubeconfig) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// delete the temporary context directory | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these things go in CommonAfterEach()? How can you know the duration the test took to run and it's pass/fail status before it is run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I moved them to CommonAfterEach()