(t *testing.T)
| 133 | } |
| 134 | |
| 135 | func TestCheckValid(t *testing.T) { |
| 136 | const path = "testdata/java.cpu" |
| 137 | |
| 138 | inbytes, err := os.ReadFile(path) |
| 139 | if err != nil { |
| 140 | t.Fatalf("failed to read profile file %q: %v", path, err) |
| 141 | } |
| 142 | p, err := Parse(bytes.NewBuffer(inbytes)) |
| 143 | if err != nil { |
| 144 | t.Fatalf("failed to parse profile %q: %s", path, err) |
| 145 | } |
| 146 | |
| 147 | for _, tc := range []struct { |
| 148 | mutateFn func(*Profile) |
| 149 | wantErr string |
| 150 | }{ |
| 151 | { |
| 152 | mutateFn: func(p *Profile) { p.SampleType = nil }, |
| 153 | wantErr: "missing sample type information", |
| 154 | }, |
| 155 | { |
| 156 | mutateFn: func(p *Profile) { p.Sample[0] = nil }, |
| 157 | wantErr: "profile has nil sample", |
| 158 | }, |
| 159 | { |
| 160 | mutateFn: func(p *Profile) { p.Sample[0].Value = append(p.Sample[0].Value, 0) }, |
| 161 | wantErr: "sample has 3 values vs. 2 types", |
| 162 | }, |
| 163 | { |
| 164 | mutateFn: func(p *Profile) { p.Sample[0].Location[0] = nil }, |
| 165 | wantErr: "sample has nil location", |
| 166 | }, |
| 167 | { |
| 168 | mutateFn: func(p *Profile) { p.Location[0] = nil }, |
| 169 | wantErr: "profile has nil location", |
| 170 | }, |
| 171 | { |
| 172 | mutateFn: func(p *Profile) { p.Mapping = append(p.Mapping, nil) }, |
| 173 | wantErr: "profile has nil mapping", |
| 174 | }, |
| 175 | { |
| 176 | mutateFn: func(p *Profile) { p.Function[0] = nil }, |
| 177 | wantErr: "profile has nil function", |
| 178 | }, |
| 179 | { |
| 180 | mutateFn: func(p *Profile) { p.Location[0].Line = append(p.Location[0].Line, Line{}) }, |
| 181 | wantErr: "has a line with nil function", |
| 182 | }, |
| 183 | } { |
| 184 | t.Run(tc.wantErr, func(t *testing.T) { |
| 185 | p := p.Copy() |
| 186 | tc.mutateFn(p) |
| 187 | if err := p.CheckValid(); err == nil { |
| 188 | t.Errorf("CheckValid(): got no error, want error %q", tc.wantErr) |
| 189 | } else if !strings.Contains(err.Error(), tc.wantErr) { |
| 190 | t.Errorf("CheckValid(): got error %v, want error %q", err, tc.wantErr) |
| 191 | } |
| 192 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…