in functional_tests/helpers.go [21:71]
func check(cbCtx *appgw.ConfigBuilderContext, expectedFilename string, stopChan chan struct{}, ctxt *k8scontext.Context, configBuilder appgw.ConfigBuilder) {
// Start the informers. This will sync the cache with the latest ingress.
err := ctxt.Run(stopChan, true, environment.GetFakeEnv())
gomega.Expect(err).ToNot(gomega.HaveOccurred())
appGW, err := configBuilder.Build(cbCtx)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
if appGW.SslCertificates != nil {
for idx := range *appGW.SslCertificates {
if (*appGW.SslCertificates)[idx].Data != nil {
*(*appGW.SslCertificates)[idx].Data = "xx"
}
}
}
jsonBlob, err := appGW.MarshalJSON()
gomega.Expect(err).ToNot(gomega.HaveOccurred())
var into map[string]interface{}
err = json.Unmarshal(jsonBlob, &into)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
jsonBlob, err = json.MarshalIndent(into, "", " ")
gomega.Expect(err).ToNot(gomega.HaveOccurred())
actualJSONTxt := string(jsonBlob)
// Repair tests
if os.Getenv("RENDER_SNAPSHOTS") != "" {
os.WriteFile(expectedFilename, []byte(actualJSONTxt), 0644)
}
expectedBytes, err := os.ReadFile(expectedFilename)
expectedJSON := strings.Trim(string(expectedBytes), "\n")
gomega.Expect(err).ToNot(gomega.HaveOccurred())
linesAct := strings.Split(actualJSONTxt, "\n")
linesExp := strings.Split(expectedJSON, "\n")
msg := fmt.Sprintf("Line counts are different: %d vs %d\nActual:\n%s\nExpected:\n%s\nfile: %s", len(linesAct), len(linesExp), actualJSONTxt, expectedJSON, expectedFilename)
gomega.Expect(len(linesAct)).To(gomega.Equal(len(linesExp)), msg)
for idx, line := range linesAct {
curatedLineAct := strings.Trim(line, " ")
curatedLineExp := strings.Trim(linesExp[idx], " ")
msg := fmt.Sprintf("Lines at index %d are different:\n%s\nvs expectedJSON:\n%s\nActual JSON:\n%s\nfrom file %s", idx, curatedLineAct, curatedLineExp, actualJSONTxt, expectedFilename)
gomega.Expect(curatedLineAct).To(gomega.Equal(curatedLineExp), msg)
}
}