Skip to content

Commit

Permalink
use t.Run
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanmar511 committed May 9, 2018
1 parent 82a75d4 commit d624f72
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions internal/driver/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,73 +434,73 @@ func TestFetchWithBase(t *testing.T) {
},
}

for _, tc := range testcases {
pprofVariables = baseVars.makeCopy()

base := make([]*string, len(tc.bases))
for i, s := range tc.bases {
base[i] = &s
}
// Allow more test cases to run in parallel.
runtime.GOMAXPROCS(len(testcases))

diffBase := make([]*string, len(tc.diffBases))
for i, s := range tc.diffBases {
diffBase[i] = &s
}

f := testFlags{
stringLists: map[string][]*string{
"base": base,
"diff_base": diffBase,
},
bools: map[string]bool{
"normalize": tc.normalize,
},
}
f.args = tc.sources
for _, tc := range testcases {
t.Run(tc.desc, func(t *testing.T) {
pprofVariables = baseVars.makeCopy()
base := make([]*string, len(tc.bases))
for i, s := range tc.bases {
base[i] = &s
}

o := setDefaults(&plugin.Options{
UI: &proftest.TestUI{T: t, AllowRx: "Local symbolization failed|Some binary filenames not available"},
Flagset: f,
})
src, _, err := parseFlags(o)
diffBase := make([]*string, len(tc.diffBases))
for i, s := range tc.diffBases {
diffBase[i] = &s
}

if tc.wantErrorMsg != "" {
if err == nil {
t.Errorf("%s: got nil, want error %q", tc.desc, tc.wantErrorMsg)
continue
f := testFlags{
stringLists: map[string][]*string{
"base": base,
"diff_base": diffBase,
},
bools: map[string]bool{
"normalize": tc.normalize,
},
}
gotErrMsg := err.Error()
if gotErrMsg != tc.wantErrorMsg {
t.Errorf("%s: got error %q, want error %q", tc.desc, gotErrMsg, tc.wantErrorMsg)
f.args = tc.sources

o := setDefaults(&plugin.Options{
UI: &proftest.TestUI{T: t, AllowRx: "Local symbolization failed|Some binary filenames not available"},
Flagset: f,
})
src, _, err := parseFlags(o)

if tc.wantErrorMsg != "" {
if err == nil {
t.Fatalf("got nil, want error %q", tc.wantErrorMsg)
}
gotErrMsg := err.Error()
if gotErrMsg != tc.wantErrorMsg {
t.Fatalf("got error %q, want error %q", gotErrMsg, tc.wantErrorMsg)
}
return
}
continue
}

if err != nil {
t.Errorf("%s: %v", tc.desc, err)
continue
}
if err != nil {
t.Fatal(err)
}

p, err := fetchProfiles(src, o)
p, err := fetchProfiles(src, o)

if err != nil {
t.Errorf("%s: %v", tc.desc, err)
continue
}

if want, got := len(tc.wantSamples), len(p.Sample); want != got {
t.Errorf("%s: got %d samples want %d", tc.desc, got, want)
continue
}
if err != nil {
t.Fatal(err)
}

for i, sample := range p.Sample {
if !reflect.DeepEqual(tc.wantSamples[i].values, sample.Value) {
t.Errorf("%s: for sample %d got values %v, want %v", tc.desc, i, sample.Value, tc.wantSamples[i])
if want, got := len(tc.wantSamples), len(p.Sample); want != got {
t.Fatalf("got %d samples want %d", got, want)
}
if !reflect.DeepEqual(tc.wantSamples[i].labels, sample.Label) {
t.Errorf("%s: for sample %d got labels %v, want %v", tc.desc, i, sample.Label, tc.wantSamples[i].labels)

for i, sample := range p.Sample {
if !reflect.DeepEqual(tc.wantSamples[i].values, sample.Value) {
t.Errorf("for sample %d got values %v, want %v", i, sample.Value, tc.wantSamples[i])
}
if !reflect.DeepEqual(tc.wantSamples[i].labels, sample.Label) {
t.Errorf("for sample %d got labels %v, want %v", i, sample.Label, tc.wantSamples[i].labels)
}
}
}
})
}
}

Expand Down

0 comments on commit d624f72

Please sign in to comment.