Skip to content
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

Improve repo test coverage in various Go packages #3390

Open
20 tasks
richscott opened this issue Feb 9, 2024 · 5 comments
Open
20 tasks

Improve repo test coverage in various Go packages #3390

richscott opened this issue Feb 9, 2024 · 5 comments
Assignees
Labels
type/tests Code Related to Tests

Comments

@richscott
Copy link
Member

richscott commented Feb 9, 2024

This is simply a list of suggested Golang files and functions in the Armada source repo that currently have low or no test coverage, and would be helpful to write new or enhanced tests for these, to verify functionality. Not every entry in here needs to be addressed in a single pull request - we will close out this ticket and create new ones with a trimmed down list of the remaining entries as necessary. Note that some of the functions are private - it may be required to change their visibility to public, depending on if the test code has Go-package access to the tested function.

To run the unit-tests and verify coverage, if you have a copy of the Armada repository, do:

$ mage tests 
$ go tool cover -func=test-reports/coverage.out > ./go-test-coverage.txt

(The output in go-test-coverage.txt will be much longer and wider than the list below, which was edited for brevity, but you will be able to search for the exact function and its coverage amount.)

Note that you can also write the coverage statistics to a HTML file, and see a colorized view of each file, showing which exact lines were/were-not covered in a test, by doing

$ go tool cover -html=test-reports/coverage.out -o coverage.html

Run go tool cover -h for more information.


  • internal/armada/server/submit_to_log.go:857: createJobs 0.0%
  • internal/armada/server/submit_to_log.go:861: createJobsObjects 0.0%
  • internal/common/database/migrations.go:91: ReadMigrations 0.0%
  • internal/common/database/migrations.go:125: ReadMigrationsFromStatik 0.0%
  • internal/executor/job/submit.go:54: SubmitJobs 0.0%
  • internal/executor/job/submit.go:58: submitJobs 0.0%
  • internal/executor/job/submit.go:84: submitWorker 0.0%
  • internal/executor/job/submit.go:113: submitPod 0.0%
  • internal/executor/job/submit.go:153: applyExecutorSpecificIngressDetails 0.0%
  • internal/executor/job/util.go:14: CreateSubmitJobFromExecutorApiJobRunLease 0.0%
  • internal/lookoutv2/repository/getjobs.go:205: sortRuns 60.0%
  • internal/lookoutv2/repository/getjobs.go:221: getJobRunTime 40.0%
  • internal/lookoutv2/repository/getjobs.go:231: makeJobRows 84.6%
  • internal/lookoutv2/repository/getjobs.go:292: makeRunRows 84.6%
  • internal/lookoutv2/repository/getjobs.go:337: makeAnnotationRows 84.6%
  • internal/scheduler/database/executor_repository.go:77: StoreExecutor 72.7%
  • internal/scheduler/scheduler_metrics.go:205: observeJobAggregates 0.0%
  • internal/scheduler/scheduler_metrics.go:221: reportNumberOfJobsConsidered 0.0%
  • internal/scheduler/scheduler_metrics.go:237: reportQueueShares 0.0%
  • pkg/client/validation/submit_file.go:38: ValidateSubmitFile 0.0%
@richscott richscott added the type/tests Code Related to Tests label Feb 9, 2024
@Bharadwajshivam28
Copy link

Hey @richscott What i understand from test coverage is that-

Suppose I have a file with 2 functions but one function is commented-

func f() int {
	return 2
}

/*func g() int {
return 4
}  */

func main() {
}

and i have a test file for it-

package main

import "testing"

func TestF(t *testing.T) {
	v := f()
	if v != 4 {
		t.Error("Fails")
	}
}

so when i run the command go test -cover then the output will be-

--- FAIL: TestF (0.00s)
    code_test.go:8: Fails
FAIL
coverage: 100.0% of statements
exit status 1
FAIL    test    0.001s

The output is because the test covered all the statements but the condition in test file failed..

If i remove the comment from function in the file-

package main

func f() int {
	return 2
}

func g() int {
return 4
}  

func main() {
}

and then run the command go test -cover then the output will be-

--- FAIL: TestF (0.00s)
    code_test.go:8: Fails
FAIL
coverage: 50.0% of statements
exit status 1
FAIL    test    0.001s

@Bharadwajshivam28
Copy link

Bharadwajshivam28 commented Feb 10, 2024

We can get a .html file also if we need to see a good view.

I can work on this issue @richscott

@richscott
Copy link
Member Author

@Bharadwajshivam28 You are exactly right. And if you run the command to generate html (go tool cover -html=test-reports/coverage.out -o coverage.html), you can open the coverage.html in your browser, and you will see the exact lines that are not covered in a test (they will be in red; code lines that are covered in a test will be in green; comments and untestable code will be in gray).

@Bharadwajshivam28
Copy link

@Bharadwajshivam28 You are exactly right. And if you run the command to generate html (go tool cover -html=test-reports/coverage.out -o coverage.html), you can open the coverage.html in your browser, and you will see the exact lines that are not covered in a test (they will be in red; code lines that are covered in a test will be in green; comments and untestable code will be in gray).

Yes i saw the process to generate html file also..

Thanks.... @richscott

@Bharadwajshivam28
Copy link

Hey @richscott Once the current PR for the function ReadMigrations gets over then I was thinking to go with the next one which is ReadMigrationsFromStatik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/tests Code Related to Tests
Projects
None yet
Development

No branches or pull requests

2 participants