|
7 | 7 | "strings"
|
8 | 8 | "testing"
|
9 | 9 |
|
| 10 | + "github.com/d4l3k/messagediff" |
10 | 11 | "gopkg.in/yaml.v2"
|
11 | 12 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
12 | 13 | "k8s.io/apimachinery/pkg/runtime"
|
@@ -37,14 +38,16 @@ func getSecret(name, namespace string, data map[string]interface{}, isTLS bool,
|
37 | 38 | object.Object["type"] = "kubernetes.io/tls"
|
38 | 39 | }
|
39 | 40 |
|
| 41 | + metadata, _ := object.Object["metadata"].(map[string]interface{}) |
| 42 | + |
40 | 43 | // if we're creating a 'raw' secret as scraped that was applied by kubectl
|
41 | 44 | if withLastApplied {
|
42 | 45 | jsonData, _ := json.Marshal(data)
|
43 |
| - object.Object["annotations"] = map[string]interface{}{ |
| 46 | + metadata["annotations"] = map[string]interface{}{ |
44 | 47 | "kubectl.kubernetes.io/last-applied-configuration": string(jsonData),
|
45 | 48 | }
|
46 | 49 | } else { // generate an expected redacted secret
|
47 |
| - object.Object["annotations"] = map[string]interface{}{ |
| 50 | + metadata["annotations"] = map[string]interface{}{ |
48 | 51 | "kubectl.kubernetes.io/last-applied-configuration": "redacted",
|
49 | 52 | }
|
50 | 53 | }
|
@@ -214,8 +217,8 @@ func TestDynamicGatherer_Fetch(t *testing.T) {
|
214 | 217 | if err == nil && test.err {
|
215 | 218 | t.Errorf("expected to get an error but didn't get one")
|
216 | 219 | }
|
217 |
| - if !reflect.DeepEqual(res, test.expected) { |
218 |
| - t.Errorf("unexpected difference: %v", diff.ObjectDiff(res, test.expected)) |
| 220 | + if diff, equal := messagediff.PrettyDiff(res, test.expected); !equal { |
| 221 | + t.Errorf("\n%s", diff) |
219 | 222 | }
|
220 | 223 | })
|
221 | 224 | }
|
|
0 commit comments