(t *testing.T)
| 215 | } |
| 216 | |
| 217 | func TestNestedStruct(t *testing.T) { |
| 218 | m := NewMapper("db") |
| 219 | |
| 220 | type Details struct { |
| 221 | Active bool `db:"active"` |
| 222 | } |
| 223 | type Asset struct { |
| 224 | Title string `db:"title"` |
| 225 | Details Details `db:"details"` |
| 226 | } |
| 227 | type Post struct { |
| 228 | Author string `db:"author,required"` |
| 229 | Asset `db:"asset"` |
| 230 | } |
| 231 | // Post columns: (author asset.title asset.details.active) |
| 232 | |
| 233 | post := Post{ |
| 234 | Author: "Joe", |
| 235 | Asset: Asset{Title: "Hello", Details: Details{Active: true}}, |
| 236 | } |
| 237 | pv := reflect.ValueOf(post) |
| 238 | |
| 239 | v := m.FieldByName(pv, "author") |
| 240 | if v.Interface().(string) != post.Author { |
| 241 | t.Errorf("Expecting %s, got %s", post.Author, v.Interface().(string)) |
| 242 | } |
| 243 | v = m.FieldByName(pv, "title") |
| 244 | if _, ok := v.Interface().(string); ok { |
| 245 | t.Errorf("Expecting field to not exist") |
| 246 | } |
| 247 | v = m.FieldByName(pv, "asset.title") |
| 248 | if v.Interface().(string) != post.Asset.Title { |
| 249 | t.Errorf("Expecting %s, got %s", post.Asset.Title, v.Interface().(string)) |
| 250 | } |
| 251 | v = m.FieldByName(pv, "asset.details.active") |
| 252 | if v.Interface().(bool) != post.Asset.Details.Active { |
| 253 | t.Errorf("Expecting %v, got %v", post.Asset.Details.Active, v.Interface().(bool)) |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | func TestInlineStruct(t *testing.T) { |
| 258 | m := NewMapperTagFunc("db", strings.ToLower, nil) |
nothing calls this directly
no test coverage detected