|
| 1 | +package reconcilers |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/require" |
| 7 | +) |
| 8 | + |
| 9 | +func TestExploreNameFromAnnotations(t *testing.T) { |
| 10 | + tests := []struct { |
| 11 | + name string |
| 12 | + annotations map[string]string |
| 13 | + fallback string |
| 14 | + want string |
| 15 | + }{ |
| 16 | + { |
| 17 | + name: "explicit explore annotation", |
| 18 | + annotations: map[string]string{"explore": "my_explore"}, |
| 19 | + fallback: "fallback", |
| 20 | + want: "my_explore", |
| 21 | + }, |
| 22 | + { |
| 23 | + name: "explicit explore takes precedence over web_open_path", |
| 24 | + annotations: map[string]string{"explore": "my_explore", "web_open_path": "/explore/other"}, |
| 25 | + fallback: "fallback", |
| 26 | + want: "my_explore", |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "web_open_path without encoding", |
| 30 | + annotations: map[string]string{"web_open_path": "/explore/my_explore"}, |
| 31 | + fallback: "fallback", |
| 32 | + want: "my_explore", |
| 33 | + }, |
| 34 | + { |
| 35 | + name: "web_open_path with percent encoding", |
| 36 | + annotations: map[string]string{"web_open_path": "/explore/publisher%20overview%20explore"}, |
| 37 | + fallback: "fallback", |
| 38 | + want: "publisher overview explore", |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "web_open_path with trailing slash", |
| 42 | + annotations: map[string]string{"web_open_path": "/explore/my_explore/"}, |
| 43 | + fallback: "fallback", |
| 44 | + want: "my_explore", |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "web_open_path with encoding and trailing slash", |
| 48 | + annotations: map[string]string{"web_open_path": "/explore/publisher%20overview/"}, |
| 49 | + fallback: "fallback", |
| 50 | + want: "publisher overview", |
| 51 | + }, |
| 52 | + { |
| 53 | + name: "non-explore web_open_path falls back", |
| 54 | + annotations: map[string]string{"web_open_path": "/canvas/my_canvas"}, |
| 55 | + fallback: "fallback", |
| 56 | + want: "fallback", |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "no annotations falls back", |
| 60 | + annotations: map[string]string{}, |
| 61 | + fallback: "fallback", |
| 62 | + want: "fallback", |
| 63 | + }, |
| 64 | + { |
| 65 | + name: "nil annotations falls back", |
| 66 | + annotations: nil, |
| 67 | + fallback: "fallback", |
| 68 | + want: "fallback", |
| 69 | + }, |
| 70 | + } |
| 71 | + for _, tt := range tests { |
| 72 | + t.Run(tt.name, func(t *testing.T) { |
| 73 | + got := exploreNameFromAnnotations(tt.annotations, tt.fallback) |
| 74 | + require.Equal(t, tt.want, got) |
| 75 | + }) |
| 76 | + } |
| 77 | +} |
0 commit comments