github.com/crossplane/upjet@v1.3.0/pkg/migration/patches_test.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package migration
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/google/go-cmp/cmp"
    11  )
    12  
    13  func TestSplitPathComponents(t *testing.T) {
    14  	tests := map[string]struct {
    15  		want []string
    16  	}{
    17  		`m['a.b.c']`: {
    18  			want: []string{`m['a.b.c']`},
    19  		},
    20  		`m["a.b.c"]`: {
    21  			want: []string{`m["a.b.c"]`},
    22  		},
    23  		`m[a.b.c]`: {
    24  			want: []string{`m[a.b.c]`},
    25  		},
    26  		`m[a.b.c.d.e]`: {
    27  			want: []string{`m[a.b.c.d.e]`},
    28  		},
    29  		`m['a.b.c.d.e']`: {
    30  			want: []string{`m['a.b.c.d.e']`},
    31  		},
    32  		`m['a.b']`: {
    33  			want: []string{`m['a.b']`},
    34  		},
    35  		`m['a']`: {
    36  			want: []string{`m['a']`},
    37  		},
    38  		`m['a'].b`: {
    39  			want: []string{`m['a']`, `b`},
    40  		},
    41  		`a`: {
    42  			want: []string{`a`},
    43  		},
    44  		`a.b`: {
    45  			want: []string{`a`, `b`},
    46  		},
    47  		`a.b.c`: {
    48  			want: []string{`a`, `b`, `c`},
    49  		},
    50  		`a.b.c.m['a.b.c']`: {
    51  			want: []string{`a`, `b`, `c`, `m['a.b.c']`},
    52  		},
    53  		`a.b.m['a.b.c'].c`: {
    54  			want: []string{`a`, `b`, `m['a.b.c']`, `c`},
    55  		},
    56  		`m['a.b.c'].a.b.c`: {
    57  			want: []string{`m['a.b.c']`, `a`, `b`, `c`},
    58  		},
    59  		`m[a.b.c].a.b.c`: {
    60  			want: []string{`m[a.b.c]`, `a`, `b`, `c`},
    61  		},
    62  		`m[0]`: {
    63  			want: []string{`m[0]`},
    64  		},
    65  		`a.b.c.m[0]`: {
    66  			want: []string{`a`, `b`, `c`, `m[0]`},
    67  		},
    68  		`m[0].a.b.c`: {
    69  			want: []string{`m[0]`, `a`, `b`, `c`},
    70  		},
    71  	}
    72  	for name, tt := range tests {
    73  		t.Run(name, func(t *testing.T) {
    74  			if diff := cmp.Diff(tt.want, splitPathComponents(name)); diff != "" {
    75  				t.Errorf("splitPathComponents(%s): -want, +got:\n%s\n", name, diff)
    76  			}
    77  		})
    78  	}
    79  }