forked from Azure/application-gateway-kubernetes-ingress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
69 lines (52 loc) · 2.57 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// -------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// --------------------------------------------------------------------------------------------
package functests
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"github.com/onsi/gomega"
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/appgw"
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/environment"
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/k8scontext"
)
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
// ioutil.WriteFile(expectedFilename, []byte(actualJSONTxt), 0644)
expectedBytes, err := ioutil.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)
}
}