(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func TestYAMLHelper(t *testing.T) { |
| 24 | helper := YAMLHelper{} |
| 25 | tests := []struct { |
| 26 | name string |
| 27 | yaml string |
| 28 | want func(*testing.T, *yaml.Node) |
| 29 | }{ |
| 30 | { |
| 31 | name: "list", |
| 32 | yaml: ` |
| 33 | - first |
| 34 | - second |
| 35 | - third`, |
| 36 | want: func(t *testing.T, node *yaml.Node) { |
| 37 | if !helper.IsList(node) { |
| 38 | t.Fatalf("IsList(node) returned false, want true") |
| 39 | } |
| 40 | |
| 41 | helper.RangeList(node, func(i int, val *yaml.Node) bool { |
| 42 | switch i { |
| 43 | case 0: |
| 44 | if !helper.IsString(val) || val.Value != "first" { |
| 45 | t.Errorf("val[%d] = %q, want %q", i, val.Value, "first") |
| 46 | } |
| 47 | case 1: |
| 48 | if !helper.IsString(val) || val.Value != "second" { |
| 49 | t.Errorf("val[%d] = %q, want %q", i, val.Value, "second") |
| 50 | } |
| 51 | case 2: |
| 52 | if !helper.IsString(val) || val.Value != "third" { |
| 53 | t.Errorf("val[%d] = %q, want %q", i, val.Value, "third") |
| 54 | } |
| 55 | } |
| 56 | return true |
| 57 | }) |
| 58 | }, |
| 59 | }, |
| 60 | { |
| 61 | name: "map", |
| 62 | yaml: ` |
| 63 | first: 1 |
| 64 | second: 2 |
| 65 | third: 3`, |
| 66 | want: func(t *testing.T, node *yaml.Node) { |
| 67 | if !helper.IsMap(node) { |
| 68 | t.Fatalf("IsMap(node) returned false, want true") |
| 69 | } |
| 70 | helper.RangeMap(node, func(key *yaml.Node, val *yaml.Node) bool { |
| 71 | if key.Value == "first" && helper.IsInteger(val) && val.Value != "1" { |
| 72 | t.Errorf("val[%q] = %q, want %q", key.Value, val.Value, "1") |
| 73 | } |
| 74 | if key.Value == "second" && helper.IsInteger(val) && val.Value != "2" { |
| 75 | t.Errorf("val[%q] = %q, want %q", key.Value, val.Value, "2") |
| 76 | } |
| 77 | if key.Value == "third" && helper.IsInteger(val) && val.Value != "3" { |
| 78 | t.Errorf("val[%q] = %q, want %q", key.Value, val.Value, "3") |
| 79 | } |
| 80 | return true |
nothing calls this directly
no test coverage detected