Skip to content

Instantly share code, notes, and snippets.

@Nivl
Last active May 25, 2020
Embed
What would you like to do?
VS Code Snippets
{
"Wrap Error": {
"prefix": "wrap",
"body": [
"errors.Wrap(err, \"could not $1\")",
],
"description": "Wrap an error using pkg/errors"
},
"Validate interface": {
"prefix": "valint",
"body": [
"// we make sure the struct implements the interface",
"var _ ${1:InterfaceName} = (*${2:StructName})(nil)",
],
"description": "Add a line to validate an interface has been correctly implemented"
},
"Test Driver Table": {
"prefix": "tdt",
"body": [
"func Test$1(t *testing.T) {",
"\ttestCases := []struct {",
"\t\tdesc string",
"\t}{",
"\t\t{",
"\t\t\tdesc:\"\",",
"\t\t},",
"\t}",
"\tfor i, tc := range testCases {",
"\t\ttc := tc",
"\t\ti := i",
"\t\tt.Run(fmt.Sprintf(\"%d/%s\", i, tc.desc), func(t *testing.T) {",
"\t\t\t$2",
"\t\t})",
"\t}",
"}",
],
"description": "Insert a tdt test"
},
"Parallel Test Driver Table": {
"prefix": "ptdt",
"body": [
"func Test$1(t *testing.T) {",
"\tt.Run(\"Parallel\", func(t *testing.T) {",
"\t\ttestCases := []struct {",
"\t\t\tdesc string",
"\t\t}{",
"\t\t\t{",
"\t\t\t\tdesc:\"\",",
"\t\t\t},",
"\t\t}",
"\t\tfor i, tc := range testCases {",
"\t\t\ttc := tc",
"\t\ti := i",
"\t\t\tt.Run(fmt.Sprintf(\"%d/%s\", i, tc.desc), func(t *testing.T) {",
"\t\t\t\tt.Parallel()",
"",
"\t\t\t\t$2",
"\t\t\t})",
"\t\t}",
"\t})",
"}",
],
"description": "Insert a parallel tdt test"
},
"Parallel Test": {
"prefix": "ptest",
"body": [
"func Test$1(t *testing.T) {",
"\tt.Run(\"Parallel\", func(t *testing.T) {",
"\t\tt.Run(\"$2\", func(t *testing.T) {",
"\t\t\tt.Parallel()",
"\t\t\t$3",
"\t\t})",
"\t})",
"}",
],
"description": "Insert a parallel test"
},
"subtest": {
"prefix": "run",
"body": [
"t.Run(\"$1\", func(t *testing.T) {",
"\t$2",
"})",
],
"description": "Insert a subtest test"
},
"parallel Subtest": {
"prefix": "prun",
"body": [
"t.Run(\"$1\", func(t *testing.T) {",
"\tt.Parallel()",
"\t$2",
"})",
],
"description": "Insert a subtest test"
},
"Mock": {
"prefix": "mock",
"body": [
"mockctrl := gomock.NewController(t)",
"defer mockctrl.Finish()",
],
"description": "Insert new mock"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment