In Python I can easily do
@pytest.mark.parametrize('input, expected', [(1, 2), [2, 3]])
def test_tutu(input, expected):
assert input + 1 == expected
How can I do the same in Go, without writing myself a loop like this:
func tutu(a int) int {
return a + 1
}
func Test_tutu(t *testing.T) {
tests := []struct {
input int
expected int
}{
{input: 1, expected: 2},
{input: 2, expected: 3},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
assert.Equal(t, tutu(tt.input), tt.expected)
})
}
}
So what would be the equivalent of this Python parametrize in Go?
def parametrize(all_args_name: str, all_values: List[Any], fn: Callable):
args_name = all_args_name.split(',')
for values in all_values:
args = {k: v for k, v in zip(args_name, values)}
fn(**args)