MCPcopy Index your code
hub / github.com/riverqueue/river / TestKeyBy

Function TestKeyBy

rivershared/util/sliceutil/slice_util_test.go:42–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestKeyBy(t *testing.T) {
43 t.Parallel()
44
45 type foo struct {
46 baz string
47 bar int
48 }
49 transform := func(f *foo) (string, int) {
50 return f.baz, f.bar
51 }
52 testCases := []struct {
53 in []*foo
54 expect map[string]int
55 }{
56 {
57 in: []*foo{{baz: "apple", bar: 1}},
58 expect: map[string]int{"apple": 1},
59 },
60 {
61 in: []*foo{{baz: "apple", bar: 1}, {baz: "banana", bar: 2}},
62 expect: map[string]int{"apple": 1, "banana": 2},
63 },
64 {
65 in: []*foo{{baz: "apple", bar: 1}, {baz: "apple", bar: 2}},
66 expect: map[string]int{"apple": 2},
67 },
68 }
69 for i, tt := range testCases {
70 t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
71 t.Parallel()
72
73 require.Equal(t, KeyBy(tt.in, transform), tt.expect)
74 })
75 }
76}
77
78func TestMap(t *testing.T) {
79 t.Parallel()

Callers

nothing calls this directly

Calls 2

KeyByFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…