|
@@ -93,7 +93,6 @@ func TestParse(t *testing.T) {
|
93
|
93
|
}
|
94
|
94
|
|
95
|
95
|
func TestParseError(t *testing.T) {
|
96
|
|
-
|
97
|
96
|
testcases := []string{
|
98
|
97
|
"",
|
99
|
98
|
"garbage text",
|
|
@@ -109,6 +108,63 @@ func TestParseError(t *testing.T) {
|
109
|
108
|
}
|
110
|
109
|
}
|
111
|
110
|
|
|
111
|
+func TestCheckValid(t *testing.T) {
|
|
112
|
+ const path = "testdata/java.cpu"
|
|
113
|
+
|
|
114
|
+ inbytes, err := ioutil.ReadFile(path)
|
|
115
|
+ if err != nil {
|
|
116
|
+ t.Fatalf("failed to read profile file %q: %v", path, err)
|
|
117
|
+ }
|
|
118
|
+ p, err := Parse(bytes.NewBuffer(inbytes))
|
|
119
|
+ if err != nil {
|
|
120
|
+ t.Fatalf("failed to parse profile %q: %s", path, err)
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ for _, tc := range []struct {
|
|
124
|
+ mutateFn func(*Profile)
|
|
125
|
+ wantErr string
|
|
126
|
+ }{
|
|
127
|
+ {
|
|
128
|
+ mutateFn: func(p *Profile) { p.SampleType = nil },
|
|
129
|
+ wantErr: "missing sample type information",
|
|
130
|
+ },
|
|
131
|
+ {
|
|
132
|
+ mutateFn: func(p *Profile) { p.Sample[0] = nil },
|
|
133
|
+ wantErr: "profile has nil sample",
|
|
134
|
+ },
|
|
135
|
+ {
|
|
136
|
+ mutateFn: func(p *Profile) { p.Sample[0].Value = append(p.Sample[0].Value, 0) },
|
|
137
|
+ wantErr: "sample has 3 values vs. 2 types",
|
|
138
|
+ },
|
|
139
|
+ {
|
|
140
|
+ mutateFn: func(p *Profile) { p.Sample[0].Location[0] = nil },
|
|
141
|
+ wantErr: "sample has nil location",
|
|
142
|
+ },
|
|
143
|
+ {
|
|
144
|
+ mutateFn: func(p *Profile) { p.Location[0] = nil },
|
|
145
|
+ wantErr: "profile has nil location",
|
|
146
|
+ },
|
|
147
|
+ {
|
|
148
|
+ mutateFn: func(p *Profile) { p.Mapping = append(p.Mapping, nil) },
|
|
149
|
+ wantErr: "profile has nil mapping",
|
|
150
|
+ },
|
|
151
|
+ {
|
|
152
|
+ mutateFn: func(p *Profile) { p.Function[0] = nil },
|
|
153
|
+ wantErr: "profile has nil function",
|
|
154
|
+ },
|
|
155
|
+ } {
|
|
156
|
+ t.Run(tc.wantErr, func(t *testing.T) {
|
|
157
|
+ p := p.Copy()
|
|
158
|
+ tc.mutateFn(p)
|
|
159
|
+ if err := p.CheckValid(); err == nil {
|
|
160
|
+ t.Errorf("CheckValid(): got no error, want error %q", tc.wantErr)
|
|
161
|
+ } else if !strings.Contains(err.Error(), tc.wantErr) {
|
|
162
|
+ t.Errorf("CheckValid(): got error %v, want error %q", err, tc.wantErr)
|
|
163
|
+ }
|
|
164
|
+ })
|
|
165
|
+ }
|
|
166
|
+}
|
|
167
|
+
|
112
|
168
|
// leaveTempfile leaves |b| in a temporary file on disk and returns the
|
113
|
169
|
// temp filename. This is useful to recover a profile when the test
|
114
|
170
|
// fails.
|