...

Source file src/edge-infra.dev/pkg/edge/gitops/fns/normalizer/findsequencenodes_test.go

Documentation: edge-infra.dev/pkg/edge/gitops/fns/normalizer

     1  //nolint:dupl
     2  package normalizer
     3  
     4  import (
     5  	"testing"
     6  
     7  	"sigs.k8s.io/kustomize/kyaml/yaml"
     8  )
     9  
    10  func TestFindSequenceNodeFieldsRecursive(t *testing.T) {
    11  	var data = `apiVersion: 'kubernetes-client.io/v1'
    12  kind: ExternalSecret
    13  metadata:
    14    name: Foo-helm-secret
    15  spec:
    16    data:
    17    - name: platform-helm-read-password
    18      key: platform-helm-read-password
    19    - name: platform-helm-read-user
    20      key: platform-helm-read-user
    21    backendType: gcpSecretsManager
    22    projectId: bar
    23  `
    24  
    25  	node, err := yaml.Parse(data)
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	} else if str, err := node.String(); err != nil {
    29  		t.Fatal(err)
    30  	} else if str != data {
    31  		t.Logf("Input:\n%s\n", data)
    32  		t.Logf("Output:\n%s\n", str)
    33  		t.Fatalf("Did not serialize node identical to input data.")
    34  	}
    35  
    36  	var fields = make(map[string]string)
    37  	findSequenceNodeFieldsRecursive(node.YNode(), "", fields)
    38  
    39  	const (
    40  		expectedKey = ".spec.data"
    41  		expectedVal = "name"
    42  	)
    43  
    44  	if len(fields) != 1 {
    45  		t.Logf("Fields: %v", fields)
    46  		t.Fatalf("Function findSequenceNodeFieldsRecursive did not find the 1 sequence field. Fount %d fields.", len(fields))
    47  	} else if value, found := fields[expectedKey]; !found {
    48  		t.Fatalf("Function findSequenceNodeFieldsRecursive did not find json path %q in fields map.", expectedKey)
    49  	} else if value != expectedVal {
    50  		t.Fatalf("Function findSequenceNodeFieldsRecursive did not find value %q for json path %q in fields map.", expectedVal, expectedKey)
    51  	}
    52  	t.Logf("Fields map: %v", fields)
    53  	t.Logf("Successfully found key %q with value %q in fields map", expectedKey, expectedVal)
    54  }
    55  

View as plain text