@@ -26,7 +26,7 @@ import (
26
26
var (
27
27
update = flag .Bool ("update" , false ,
28
28
`update the expected output of these tests,
29
- only use when the expected output is outdated and you are sure your output is correct` )
29
+ only use when the expected output is outdated and you are sure your output is correct` )
30
30
)
31
31
32
32
func TestMain (m * testing.M ) {
@@ -70,79 +70,133 @@ func getExpectedFilePath(relativePath string) (string, error) {
70
70
}
71
71
72
72
//nolint:funlen,gocognit
73
- func TestGenSupFromSrcCode (t * testing.T ) {
73
+ func TestGenFromSrcCode (t * testing.T ) {
74
74
t .Parallel ()
75
75
tests := map [string ]struct {
76
76
relativePath string
77
77
wantErr bool
78
- filter map [string ]struct {}
79
- override map [string ][]Mask
78
+ config GenerateConfig
80
79
}{
81
80
"normalDirectiveDefinition_pass" : {
82
81
relativePath : "normalDefinition" ,
83
- wantErr : false ,
82
+ config : GenerateConfig {
83
+ DirectiveMapName : "myDirectives" ,
84
+ MatchFuncName : "MyMatchFn" ,
85
+ },
86
+ wantErr : false ,
84
87
},
85
88
"unknownBitmask_fail" : {
86
89
relativePath : "unknownBitmask" ,
87
- wantErr : true ,
90
+ config : GenerateConfig {
91
+ DirectiveMapName : "directives" ,
92
+ MatchFuncName : "Match" ,
93
+ },
94
+ wantErr : true ,
88
95
},
89
96
"noDirectivesDefinition_fail" : {
90
97
relativePath : "noDirectives" ,
91
- wantErr : true ,
98
+ config : GenerateConfig {
99
+ DirectiveMapName : "directives" ,
100
+ MatchFuncName : "Match" ,
101
+ },
102
+ wantErr : true ,
92
103
},
93
104
// If one directive was defined in several files, we should keep all
94
105
// of the bitmask definitions
95
106
"directiveRepeatDefine_pass" : {
96
107
relativePath : "repeatDefine" ,
108
+ config : GenerateConfig {
109
+ DirectiveMapName : "directives" ,
110
+ MatchFuncName : "Match" ,
111
+ },
112
+ wantErr : false ,
97
113
},
98
114
// If there are comments in directive definition, we should ignore them
99
115
"commentsInDefinition_pass" : {
100
116
relativePath : "commentsInDefinition" ,
117
+ config : GenerateConfig {
118
+ DirectiveMapName : "directives" ,
119
+ MatchFuncName : "Match" ,
120
+ },
121
+ wantErr : false ,
101
122
},
102
123
"genFromSingleFile_pass" : {
103
124
relativePath : "single_file.c" ,
125
+ config : GenerateConfig {
126
+ DirectiveMapName : "directives" ,
127
+ MatchFuncName : "Match" ,
128
+ },
129
+ wantErr : false ,
104
130
},
105
131
"fullNgxBitmaskCover_pass" : {
106
132
relativePath : "fullNgxBitmaskCover" ,
133
+ config : GenerateConfig {
134
+ DirectiveMapName : "directives" ,
135
+ MatchFuncName : "Match" ,
136
+ },
137
+ wantErr : false ,
107
138
},
108
139
"testFilter_pass" : {
109
140
relativePath : "filter" ,
110
- filter : map [string ]struct {}{"my_directive_2" : {}, "my_directive_3" : {}},
141
+ config : GenerateConfig {
142
+ DirectiveMapName : "directives" ,
143
+ MatchFuncName : "Match" ,
144
+ Filter : map [string ]struct {}{"my_directive_2" : {}, "my_directive_3" : {}},
145
+ },
111
146
},
112
147
"testOverride_pass" : {
113
148
relativePath : "override" ,
114
- override : map [string ][]Mask {
115
- "my_directive_1" : {
116
- Mask {"ngxHTTPMainConf" , "ngxConfTake1" },
117
- Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
118
- },
119
- "my_directive_3" : {
120
- Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
121
- Mask {"ngxHTTPMainConf" , "ngxConfTake3" },
149
+ config : GenerateConfig {
150
+ DirectiveMapName : "directives" ,
151
+ MatchFuncName : "Match" ,
152
+ Override : map [string ][]Mask {
153
+ "my_directive_1" : {
154
+ Mask {"ngxHTTPMainConf" , "ngxConfTake1" },
155
+ Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
156
+ },
157
+ "my_directive_3" : {
158
+ Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
159
+ Mask {"ngxHTTPMainConf" , "ngxConfTake3" },
160
+ },
122
161
},
123
162
},
163
+ wantErr : false ,
124
164
},
125
165
"testFilterAndOverride_pass" : {
126
166
relativePath : "filterAndOverride" ,
127
- filter : map [string ]struct {}{
128
- "my_directive_1" : {},
129
- "my_directive_2" : {},
130
- "my_directive_3" : {},
131
- },
132
- override : map [string ][]Mask {
133
- "my_directive_1" : {
134
- Mask {"ngxHTTPMainConf" , "ngxConfTake1" },
135
- Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
167
+ config : GenerateConfig {
168
+ Filter : map [string ]struct {}{
169
+ "my_directive_1" : {},
170
+ "my_directive_2" : {},
171
+ "my_directive_3" : {},
136
172
},
137
- "my_directive_3" : {
138
- Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
139
- Mask {"ngxHTTPMainConf" , "ngxConfTake3" },
140
- },
141
- "my_directive_4" : {
142
- Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
143
- Mask {"ngxHTTPMainConf" , "ngxConfTake3" },
173
+ Override : map [string ][]Mask {
174
+ "my_directive_1" : {
175
+ Mask {"ngxHTTPMainConf" , "ngxConfTake1" },
176
+ Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
177
+ },
178
+ "my_directive_3" : {
179
+ Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
180
+ Mask {"ngxHTTPMainConf" , "ngxConfTake3" },
181
+ },
182
+ "my_directive_4" : {
183
+ Mask {"ngxHTTPMainConf" , "ngxConfTake2" },
184
+ Mask {"ngxHTTPMainConf" , "ngxConfTake3" },
185
+ },
144
186
},
187
+ DirectiveMapName : "directives" ,
188
+ MatchFuncName : "Match" ,
189
+ },
190
+ wantErr : false ,
191
+ },
192
+ "withMatchFuncComment_pass" : {
193
+ relativePath : "withMatchFuncComment" ,
194
+ config : GenerateConfig {
195
+ DirectiveMapName : "myDirectives" ,
196
+ MatchFuncName : "MyMatchFn" ,
197
+ MatchFuncComment : "This is a matchFunc" ,
145
198
},
199
+ wantErr : false ,
146
200
},
147
201
}
148
202
for name , tc := range tests {
@@ -157,7 +211,7 @@ func TestGenSupFromSrcCode(t *testing.T) {
157
211
158
212
var buf bytes.Buffer
159
213
160
- err = genFromSrcCode (codePath , "directives" , "Match" , & buf , tc .filter , tc . override )
214
+ err = genFromSrcCode (codePath , & buf , tc .config )
161
215
162
216
if tc .wantErr {
163
217
require .Error (t , err )
0 commit comments