File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed
Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -133,29 +133,29 @@ func NewExampleCommand(clients *shared.ClientFactory) *cobra.Command {
133133
134134### Table-Driven Test Conventions
135135
136- ** Preferred: Slice pattern** - uses ` tc ` for test case variable:
136+ ** Preferred: Map pattern** - uses ` tc ` for test case variable:
137137``` go
138- tests := []struct {
139- name string
138+ tests := map [string ]struct {
140139 input string
141140 expected string
142141}{...}
143- for _ , tc := range tests {
144- t.Run (tc. name , func (t *testing.T ) {
142+ for name , tc := range tests {
143+ t.Run (name, func (t *testing.T ) {
145144 // use tc.field
146145 })
147146}
148147```
149148
150- ** Legacy: Map pattern** - uses ` tt ` for test case variable (do not use for new tests):
149+ ** Legacy: Slice pattern** - uses ` tc ` for test case variable (do not use for new tests):
151150``` go
152- tests := map [string ]struct {
151+ tests := []struct {
152+ name string
153153 input string
154154 expected string
155155}{...}
156- for name , tt := range tests {
157- t.Run (name, func (t *testing.T ) {
158- // use tt .field
156+ for _ , tc := range tests {
157+ t.Run (tc. name , func (t *testing.T ) {
158+ // use tc .field
159159 })
160160}
161161```
You can’t perform that action at this time.
0 commit comments