@@ -25,7 +25,7 @@ func TestLibAsCLIIntegration(t *testing.T) {
2525 tests := map [string ]struct {
2626 config func () lib.PrometheusSLOGeneratorConfig
2727 inFilePath string
28- resultFormatter func (t * testing.T , result model.PromSLOGroupResult ) []byte
28+ resultFormatter func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte
2929 expOutFilePath string
3030 expGenErr bool
3131 }{
@@ -43,9 +43,9 @@ func TestLibAsCLIIntegration(t *testing.T) {
4343 },
4444 inFilePath : "../../test/integration/prometheus/testdata/in-base.yaml" ,
4545 expOutFilePath : "../../test/integration/prometheus/testdata/out-base.yaml.tpl" ,
46- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
46+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
4747 var b bytes.Buffer
48- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
48+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
4949 require .NoError (t , err )
5050 return b .Bytes ()
5151 },
@@ -57,10 +57,10 @@ func TestLibAsCLIIntegration(t *testing.T) {
5757 },
5858 inFilePath : "../../test/integration/prometheus/testdata/in-base-k8s.yaml" ,
5959 expOutFilePath : "../../test/integration/prometheus/testdata/out-base-k8s.yaml.tpl" ,
60- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
60+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
6161 var b bytes.Buffer
6262 kmeta := model.K8sMeta {Name : "svc" , Namespace : "test-ns" }
63- err := lib .WriteResultAsK8sPrometheusOperator (t .Context (), kmeta , result , & b )
63+ err := gen .WriteResultAsK8sPrometheusOperator (t .Context (), kmeta , result , & b )
6464 require .NoError (t , err )
6565 return b .Bytes ()
6666 },
@@ -72,9 +72,9 @@ func TestLibAsCLIIntegration(t *testing.T) {
7272 },
7373 inFilePath : "../../test/integration/prometheus/testdata/in-openslo.yaml" ,
7474 expOutFilePath : "../../test/integration/prometheus/testdata/out-openslo.yaml.tpl" ,
75- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
75+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
7676 var b bytes.Buffer
77- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
77+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
7878 require .NoError (t , err )
7979 return b .Bytes ()
8080 },
@@ -89,9 +89,9 @@ func TestLibAsCLIIntegration(t *testing.T) {
8989 },
9090 inFilePath : "../../test/integration/prometheus/testdata/in-base.yaml" ,
9191 expOutFilePath : "../../test/integration/prometheus/testdata/out-base-28d.yaml.tpl" ,
92- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
92+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
9393 var b bytes.Buffer
94- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
94+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
9595 require .NoError (t , err )
9696 return b .Bytes ()
9797 },
@@ -107,9 +107,9 @@ func TestLibAsCLIIntegration(t *testing.T) {
107107 },
108108 inFilePath : "../../test/integration/prometheus/testdata/in-base.yaml" ,
109109 expOutFilePath : "../../test/integration/prometheus/testdata/out-base-custom-windows-7d.yaml.tpl" ,
110- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
110+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
111111 var b bytes.Buffer
112- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
112+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
113113 require .NoError (t , err )
114114 return b .Bytes ()
115115 },
@@ -124,9 +124,9 @@ func TestLibAsCLIIntegration(t *testing.T) {
124124 },
125125 inFilePath : "../../test/integration/prometheus/testdata/in-base.yaml" ,
126126 expOutFilePath : "../../test/integration/prometheus/testdata/out-base-extra-labels.yaml.tpl" ,
127- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
127+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
128128 var b bytes.Buffer
129- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
129+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
130130 require .NoError (t , err )
131131 return b .Bytes ()
132132 },
@@ -138,14 +138,14 @@ func TestLibAsCLIIntegration(t *testing.T) {
138138 },
139139 inFilePath : "../../test/integration/prometheus/testdata/in-base.yaml" ,
140140 expOutFilePath : "../../test/integration/prometheus/testdata/out-base-no-alerts.yaml.tpl" ,
141- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
141+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
142142
143143 for i := range result .SLOResults {
144144 result .SLOResults [i ].PrometheusRules .AlertRules = model.PromRuleGroup {}
145145 }
146146
147147 var b bytes.Buffer
148- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
148+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
149149 require .NoError (t , err )
150150 return b .Bytes ()
151151 },
@@ -157,15 +157,15 @@ func TestLibAsCLIIntegration(t *testing.T) {
157157 },
158158 inFilePath : "../../test/integration/prometheus/testdata/in-base.yaml" ,
159159 expOutFilePath : "../../test/integration/prometheus/testdata/out-base-no-recordings.yaml.tpl" ,
160- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
160+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
161161 // Remove alerts.
162162 for i := range result .SLOResults {
163163 result .SLOResults [i ].PrometheusRules .SLIErrorRecRules = model.PromRuleGroup {}
164164 result .SLOResults [i ].PrometheusRules .MetadataRecRules = model.PromRuleGroup {}
165165 }
166166
167167 var b bytes.Buffer
168- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
168+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
169169 require .NoError (t , err )
170170 return b .Bytes ()
171171 },
@@ -180,9 +180,9 @@ func TestLibAsCLIIntegration(t *testing.T) {
180180 },
181181 inFilePath : "../../test/integration/prometheus/testdata/in-sli-plugin.yaml" ,
182182 expOutFilePath : "../../test/integration/prometheus/testdata/out-sli-plugin.yaml.tpl" ,
183- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
183+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
184184 var b bytes.Buffer
185- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
185+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
186186 require .NoError (t , err )
187187 return b .Bytes ()
188188 },
@@ -197,9 +197,9 @@ func TestLibAsCLIIntegration(t *testing.T) {
197197 },
198198 inFilePath : "../../test/integration/prometheus/testdata/in-slo-plugin.yaml" ,
199199 expOutFilePath : "../../test/integration/prometheus/testdata/out-slo-plugin.yaml.tpl" ,
200- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
200+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
201201 var b bytes.Buffer
202- err := lib .WriteResultAsPrometheusStd (t .Context (), result , & b )
202+ err := gen .WriteResultAsPrometheusStd (t .Context (), result , & b )
203203 require .NoError (t , err )
204204 return b .Bytes ()
205205 },
@@ -214,10 +214,10 @@ func TestLibAsCLIIntegration(t *testing.T) {
214214 },
215215 inFilePath : "../../test/integration/prometheus/testdata/in-slo-plugin-k8s.yaml" ,
216216 expOutFilePath : "../../test/integration/prometheus/testdata/out-slo-plugin-k8s.yaml.tpl" ,
217- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte {
217+ resultFormatter : func (t * testing.T , gen * lib. PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
218218 var b bytes.Buffer
219219 kmeta := model.K8sMeta {Name : "svc" , Namespace : "test-ns" }
220- err := lib .WriteResultAsK8sPrometheusOperator (t .Context (), kmeta , result , & b )
220+ err := gen .WriteResultAsK8sPrometheusOperator (t .Context (), kmeta , result , & b )
221221 require .NoError (t , err )
222222 return b .Bytes ()
223223 },
@@ -227,18 +227,22 @@ func TestLibAsCLIIntegration(t *testing.T) {
227227 config : func () lib.PrometheusSLOGeneratorConfig {
228228 return lib.PrometheusSLOGeneratorConfig {CallerAgent : lib .CallerAgentCLI }
229229 },
230- inFilePath : "../../test/integration/prometheus/testdata/in-multifile.yaml" ,
231- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte { return nil },
232- expGenErr : true ,
230+ inFilePath : "../../test/integration/prometheus/testdata/in-multifile.yaml" ,
231+ resultFormatter : func (t * testing.T , gen * lib.PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
232+ return nil
233+ },
234+ expGenErr : true ,
233235 },
234236
235237 "A multifile Kubernetes case (Not supported)." : {
236238 config : func () lib.PrometheusSLOGeneratorConfig {
237239 return lib.PrometheusSLOGeneratorConfig {CallerAgent : lib .CallerAgentCLI }
238240 },
239- inFilePath : "../../test/integration/prometheus/testdata/in-multifile-k8s.yaml" ,
240- resultFormatter : func (t * testing.T , result model.PromSLOGroupResult ) []byte { return nil },
241- expGenErr : true ,
241+ inFilePath : "../../test/integration/prometheus/testdata/in-multifile-k8s.yaml" ,
242+ resultFormatter : func (t * testing.T , gen * lib.PrometheusSLOGenerator , result model.PromSLOGroupResult ) []byte {
243+ return nil
244+ },
245+ expGenErr : true ,
242246 },
243247 }
244248
@@ -256,10 +260,9 @@ func TestLibAsCLIIntegration(t *testing.T) {
256260 result , err := gen .GenerateFromRaw (t .Context (), expInData )
257261 if test .expGenErr {
258262 assert .Error (err )
259- return
260263 } else if assert .NoError (err ) {
261264 // Check result.
262- resultOutData := test .resultFormatter (t , * result )
265+ resultOutData := test .resultFormatter (t , gen , * result )
263266 expOutData := getExpData (t , test .expOutFilePath )
264267 assert .Equal (string (expOutData ), string (resultOutData ))
265268 }
0 commit comments