Skip to content

feat: runner go test name#64

Open
maxwelbm wants to merge 3 commits into
crispgm:mainfrom
maxwelbm:feat/test_name
Open

feat: runner go test name#64
maxwelbm wants to merge 3 commits into
crispgm:mainfrom
maxwelbm:feat/test_name

Conversation

@maxwelbm

@maxwelbm maxwelbm commented Jul 29, 2023

Copy link
Copy Markdown

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

crispgm commented Aug 1, 2023

Copy link
Copy Markdown
Owner

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

@maxwelbm

maxwelbm commented Aug 1, 2023

Copy link
Copy Markdown
Author

@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

Soyvor commented Aug 10, 2023

Copy link
Copy Markdown

Can i participate in this project too ?

@crispgm

crispgm commented Aug 10, 2023

Copy link
Copy Markdown
Owner

Can i participate in this project too ?

Yes, of course :)

@crispgm

crispgm commented Aug 17, 2023

Copy link
Copy Markdown
Owner

@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
Copy Markdown
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