TestFilter ensures that commands with a regexp filter argument return an error if there are no results.
(t *testing.T)
| 105 | // TestFilter ensures that commands with a regexp filter argument return an |
| 106 | // error if there are no results. |
| 107 | func TestFilter(t *testing.T) { |
| 108 | const filter = "doesNotExist" |
| 109 | |
| 110 | tests := []struct { |
| 111 | name string |
| 112 | format int |
| 113 | }{ |
| 114 | { |
| 115 | name: "list", |
| 116 | format: List, |
| 117 | }, |
| 118 | { |
| 119 | name: "disasm", |
| 120 | format: Dis, |
| 121 | }, |
| 122 | { |
| 123 | // N.B. Tree with a Symbol is "peek". |
| 124 | name: "peek", |
| 125 | format: Tree, |
| 126 | }, |
| 127 | } |
| 128 | for _, tc := range tests { |
| 129 | t.Run(tc.name, func(t *testing.T) { |
| 130 | rpt := New(testProfile.Copy(), &Options{ |
| 131 | OutputFormat: tc.format, |
| 132 | Symbol: regexp.MustCompile(filter), |
| 133 | SampleValue: func(v []int64) int64 { return v[1] }, |
| 134 | SampleUnit: testProfile.SampleType[1].Unit, |
| 135 | }) |
| 136 | |
| 137 | var buf bytes.Buffer |
| 138 | err := Generate(&buf, rpt, &binutils.Binutils{}) |
| 139 | if err == nil { |
| 140 | t.Fatalf("Generate got nil, want error; buf = %s", buf.String()) |
| 141 | } |
| 142 | if !strings.Contains(err.Error(), filter) { |
| 143 | t.Errorf("Error got %v, want it to contain %q", err, filter) |
| 144 | } |
| 145 | }) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // testM contains mappings for fake profiles used in tests. |
| 150 | var testM = []*profile.Mapping{ |