|
| 1 | +// Copyright © 2025 Meroxa, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package config |
| 16 | + |
| 17 | +import ( |
| 18 | + "reflect" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "gopkg.in/yaml.v3" |
| 22 | +) |
| 23 | + |
| 24 | +func TestStringOrSlice_UnmarshalYAML(t *testing.T) { |
| 25 | + testCases := []struct { |
| 26 | + input string |
| 27 | + want StringList |
| 28 | + }{{ |
| 29 | + input: `"single"`, |
| 30 | + want: StringList{"single"}, |
| 31 | + }, { |
| 32 | + input: `["one", "two", "three"]`, |
| 33 | + want: StringList{"one", "two", "three"}, |
| 34 | + }, { |
| 35 | + input: `- foo |
| 36 | +- bar |
| 37 | +- baz`, |
| 38 | + want: StringList{"foo", "bar", "baz"}, |
| 39 | + }} |
| 40 | + |
| 41 | + for _, tc := range testCases { |
| 42 | + t.Run(tc.input, func(t *testing.T) { |
| 43 | + var result StringList |
| 44 | + err := yaml.Unmarshal([]byte(tc.input), &result) |
| 45 | + if err != nil { |
| 46 | + t.Fatalf("unexpected error: %v", err) |
| 47 | + } |
| 48 | + if !reflect.DeepEqual(result, tc.want) { |
| 49 | + t.Errorf("got: %v, want: %v", result, tc.want) |
| 50 | + } |
| 51 | + }) |
| 52 | + } |
| 53 | +} |
0 commit comments