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

feat: runner go test name #64

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

maxwelbm
Copy link

@maxwelbm maxwelbm commented Jul 29, 2023

Hello, I felt the need to run isolated tests and added a new command GoTestName to improve the work with tests

Example

case I want to run in the table testing model name: "Lorem ipsum dolor sit amet, consectetur"

go test -run TestExample/Lorem_ipsum_dolor_sit_amet,_consectetur_adipiscing_elit 

@maxwelbm maxwelbm changed the title feat: test name feat: runner go test name Jul 29, 2023
@crispgm
Copy link
Owner

crispgm commented Aug 1, 2023

@maxwelbm sounds good. would you please showing a go example file for testing?

@maxwelbm
Copy link
Author

maxwelbm commented Aug 1, 2023

@maxwelbm sounds good. would you please showing a go example file for testing?

https://go.dev/blog/subtests

an example of the test table that is the golang test pattern
https://github.com/aziontech/azion-cli/blob/dev/pkg/cmd/edge_applications/edge_applications_test.go

@crispgm

@Soyvor
Copy link

Soyvor commented Aug 10, 2023

Can i participate in this project too ?

@crispgm
Copy link
Owner

crispgm commented Aug 10, 2023

Can i participate in this project too ?

Yes, of course :)

@crispgm
Copy link
Owner

crispgm commented Aug 17, 2023

@maxwelbm I have issue with this PR, since I just fully investigated how sub tests work.

  1. GoTestName always shows testing: warning: no tests to run
  2. GoTestName needs no argument. I think we may allow user to pass on his/her own.
  3. Tiny Luacheck issues need to be fixed

My test Go codes:

func testFunc(a int) int {
	return a + 1
}
func TestTable(t *testing.T) {
	testCases := []struct {
		a    int
		want int
	}{
		{1, 2},
		{2, 3},
		{3, 4},
		{4, 6},
	}
	for _, tc := range testCases {
		t.Run(fmt.Sprintf("%d in %d", tc.a, tc.want), func(t *testing.T) {
			if testFunc(tc.a) != tc.want {
				t.Errorf("%d not in %d", tc.a, tc.want)
			}
		})
	}
}

@maxwelbm
Copy link
Author

@crispgm in the example you presented it is not possible to apply, but this test table model without the name is not used, because in this case it only runs the entire block of tests

func TestTable(t *testing.T) {
	testCases := []struct {
                name string
		a    int
		want int
	}{
                // go test -run TestTable/case_01
		{name: "case 01", 1, 2}, // execute this isolated block
		{2, 3},
		{3, 4},
		{4, 6},
	}
	for _, tc := range testCases {
		t.Run(fmt.Sprintf("%d in %d", tc.a, tc.want), func(t *testing.T) {
			if testFunc(tc.a) != tc.want {
				t.Errorf("%d not in %d", tc.a, tc.want)
			}
		})
	}
}

Answers
1 - it always shows because it doesn't have the expected name tag
2 - if you allow the user to pass on their own, it slows down the process
3 - I will send corrections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants