(t *testing.T)
| 103 | } |
| 104 | |
| 105 | func Test_assignFieldMapping(t *testing.T) { |
| 106 | fieldNames := []string{"name0", "name1"} |
| 107 | fieldByName := func(n string) (FieldIndex, bool) { |
| 108 | for idx, name := range fieldNames { |
| 109 | if n == name { |
| 110 | return FieldIndex(idx), true |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return 0, false |
| 115 | } |
| 116 | |
| 117 | cfgFields := ConfigFields{ |
| 118 | Names: []string{"name0", "name1"}, |
| 119 | } |
| 120 | |
| 121 | tests := []struct { |
| 122 | name string |
| 123 | cfg *Config |
| 124 | comp Components |
| 125 | wantErr bool |
| 126 | }{ |
| 127 | { |
| 128 | name: "only in Config", |
| 129 | cfg: &Config{ |
| 130 | Fields: cfgFields, |
| 131 | }, |
| 132 | }, |
| 133 | { |
| 134 | name: "only in Components", |
| 135 | cfg: &Config{}, |
| 136 | comp: Components{ |
| 137 | FieldByName: fieldByName, |
| 138 | FieldNames: fieldNames, |
| 139 | }, |
| 140 | }, |
| 141 | |
| 142 | // error cases |
| 143 | { |
| 144 | name: "nothing set", |
| 145 | cfg: &Config{}, comp: Components{}, |
| 146 | wantErr: true, |
| 147 | }, |
| 148 | { |
| 149 | name: "FieldByName but not FieldName", |
| 150 | cfg: &Config{}, |
| 151 | comp: Components{ |
| 152 | FieldByName: fieldByName, |
| 153 | }, |
| 154 | wantErr: true, |
| 155 | }, |
| 156 | { |
| 157 | name: "FieldName but not FieldByName", |
| 158 | cfg: &Config{}, |
| 159 | comp: Components{ |
| 160 | FieldNames: fieldNames, |
| 161 | }, |
| 162 | wantErr: true, |
nothing calls this directly
no test coverage detected