MCPcopy Create free account
hub / github.com/gavv/httpexpect / TestObject_Transform

Function TestObject_Transform

object_test.go:1535–1664  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1533}
1534
1535func TestObject_Transform(t *testing.T) {
1536 t.Run("check index", func(t *testing.T) {
1537 reporter := newMockReporter(t)
1538 object := NewObject(reporter, map[string]interface{}{
1539 "foo": "123",
1540 "bar": "456",
1541 "baz": "baz",
1542 })
1543
1544 newObject := object.Transform(func(key string, value interface{}) interface{} {
1545 if v, ok := value.(string); ok {
1546 switch v {
1547 case "123":
1548 assert.Equal(t, "foo", key)
1549 case "456":
1550 assert.Equal(t, "bar", key)
1551 case "baz":
1552 assert.Equal(t, "baz", key)
1553 }
1554 }
1555 return value
1556 })
1557
1558 newObject.chain.assert(t, success)
1559 })
1560
1561 t.Run("transform value", func(t *testing.T) {
1562 reporter := newMockReporter(t)
1563 object := NewObject(reporter, map[string]interface{}{
1564 "foo": "123",
1565 "bar": "456",
1566 "baz": "b",
1567 })
1568
1569 newObject := object.Transform(func(_ string, value interface{}) interface{} {
1570 if v, ok := value.(string); ok {
1571 return "Hello " + v
1572 }
1573 return nil
1574 })
1575
1576 assert.Equal(t,
1577 map[string]interface{}{
1578 "foo": "Hello 123",
1579 "bar": "Hello 456",
1580 "baz": "Hello b",
1581 },
1582 newObject.value,
1583 )
1584 })
1585
1586 t.Run("empty object", func(t *testing.T) {
1587 reporter := newMockReporter(t)
1588 object := NewObject(reporter, map[string]interface{}{
1589 "foo": "123",
1590 "bar": "456",
1591 "baz": "b",
1592 })

Callers

nothing calls this directly

Calls 7

TransformMethod · 0.95
newMockReporterFunction · 0.85
NewObjectFunction · 0.85
assertMethod · 0.80
myIntTypeAlias · 0.70
EqualMethod · 0.45
RawMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…