瀏覽代碼

Use buffer as a var instead of NewBuffer(nil). (#312)

Alexey Alexandrov 7 年之前
父節點
當前提交
35174474cc
No account linked to committer's email address
共有 4 個文件被更改,包括 14 次插入14 次删除
  1. 2
    2
      internal/report/report_test.go
  2. 2
    2
      internal/report/source_test.go
  3. 7
    7
      profile/profile_test.go
  4. 3
    3
      profile/proto_test.go

+ 2
- 2
internal/report/report_test.go 查看文件

68
 			want: path + "source.dot",
68
 			want: path + "source.dot",
69
 		},
69
 		},
70
 	} {
70
 	} {
71
-		b := bytes.NewBuffer(nil)
72
-		if err := Generate(b, tc.rpt, &binutils.Binutils{}); err != nil {
71
+		var b bytes.Buffer
72
+		if err := Generate(&b, tc.rpt, &binutils.Binutils{}); err != nil {
73
 			t.Fatalf("%s: %v", tc.want, err)
73
 			t.Fatalf("%s: %v", tc.want, err)
74
 		}
74
 		}
75
 
75
 

+ 2
- 2
internal/report/source_test.go 查看文件

25
 		SampleValue:  func(v []int64) int64 { return v[1] },
25
 		SampleValue:  func(v []int64) int64 { return v[1] },
26
 		SampleUnit:   cpu.SampleType[1].Unit,
26
 		SampleUnit:   cpu.SampleType[1].Unit,
27
 	})
27
 	})
28
-	buf := bytes.NewBuffer(nil)
29
-	if err := Generate(buf, rpt, &binutils.Binutils{}); err != nil {
28
+	var buf bytes.Buffer
29
+	if err := Generate(&buf, rpt, &binutils.Binutils{}); err != nil {
30
 		t.Fatalf("could not generate weblist: %v", err)
30
 		t.Fatalf("could not generate weblist: %v", err)
31
 	}
31
 	}
32
 	output := buf.String()
32
 	output := buf.String()

+ 7
- 7
profile/profile_test.go 查看文件

73
 		}
73
 		}
74
 
74
 
75
 		// Reencode and decode.
75
 		// Reencode and decode.
76
-		bw := bytes.NewBuffer(nil)
77
-		if err := p.Write(bw); err != nil {
76
+		var bw bytes.Buffer
77
+		if err := p.Write(&bw); err != nil {
78
 			t.Fatalf("%s: %v", source, err)
78
 			t.Fatalf("%s: %v", source, err)
79
 		}
79
 		}
80
-		if p, err = Parse(bw); err != nil {
80
+		if p, err = Parse(&bw); err != nil {
81
 			t.Fatalf("%s: %v", source, err)
81
 			t.Fatalf("%s: %v", source, err)
82
 		}
82
 		}
83
 		js2 := p.String()
83
 		js2 := p.String()
111
 func TestParseConcatentated(t *testing.T) {
111
 func TestParseConcatentated(t *testing.T) {
112
 	prof := testProfile1.Copy()
112
 	prof := testProfile1.Copy()
113
 	// Write the profile twice to buffer to create concatented profile.
113
 	// Write the profile twice to buffer to create concatented profile.
114
-	buf := bytes.NewBuffer(nil)
115
-	prof.Write(buf)
116
-	prof.Write(buf)
117
-	_, err := Parse(buf)
114
+	var buf bytes.Buffer
115
+	prof.Write(&buf)
116
+	prof.Write(&buf)
117
+	_, err := Parse(&buf)
118
 	if err == nil {
118
 	if err == nil {
119
 		t.Fatalf("got nil, want error")
119
 		t.Fatalf("got nil, want error")
120
 	}
120
 	}

+ 3
- 3
profile/proto_test.go 查看文件

151
 
151
 
152
 func TestMarshalUnmarshal(t *testing.T) {
152
 func TestMarshalUnmarshal(t *testing.T) {
153
 	// Write the profile, parse it, and ensure they're equal.
153
 	// Write the profile, parse it, and ensure they're equal.
154
-	buf := bytes.NewBuffer(nil)
155
-	all.Write(buf)
156
-	all2, err := Parse(buf)
154
+	var buf bytes.Buffer
155
+	all.Write(&buf)
156
+	all2, err := Parse(&buf)
157
 	if err != nil {
157
 	if err != nil {
158
 		t.Fatal(err)
158
 		t.Fatal(err)
159
 	}
159
 	}