Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 9cc5395

Browse files
authored
add wrapper around ioutil.ReadFile. (#226)
* add wrapper around ioutil.ReadFile. * rename ReadFromFile to ReadFile * refactor interna/ioutil_wrapper.go to util_test.go
1 parent 3504ffa commit 9cc5395

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

metrics_proto_api_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package stackdriver_test
1717
import (
1818
"context"
1919
"fmt"
20-
"io/ioutil"
2120
"net"
2221
"strings"
2322
"sync"
@@ -427,7 +426,7 @@ func readTestCaseFromFiles(t *testing.T, filename string) *testCases {
427426
}
428427

429428
// Read input Metrics proto.
430-
f, err := ioutil.ReadFile("testdata/" + filename + "/inMetrics.txt")
429+
f, err := readFile("testdata/" + filename + "/inMetrics.txt")
431430
if err != nil {
432431
t.Fatalf("error opening in file " + filename)
433432
}
@@ -443,7 +442,7 @@ func readTestCaseFromFiles(t *testing.T, filename string) *testCases {
443442
}
444443

445444
// Read expected output CreateMetricDescriptorRequest proto.
446-
f, err = ioutil.ReadFile("testdata/" + filename + "/outMDR.txt")
445+
f, err = readFile("testdata/" + filename + "/outMDR.txt")
447446
if err != nil {
448447
t.Fatalf("error opening in file " + filename)
449448
}
@@ -461,7 +460,7 @@ func readTestCaseFromFiles(t *testing.T, filename string) *testCases {
461460
}
462461

463462
// Read expected output CreateTimeSeriesRequest proto.
464-
f, err = ioutil.ReadFile("testdata/" + filename + "/outTSR.txt")
463+
f, err = readFile("testdata/" + filename + "/outTSR.txt")
465464
if err != nil {
466465
t.Fatalf("error opening in file " + filename)
467466
}
@@ -480,7 +479,7 @@ func readTestCaseFromFiles(t *testing.T, filename string) *testCases {
480479

481480
func readTestResourcesFiles(t *testing.T, filename string) ([]*resourcepb.Resource, []*monitoredrespb.MonitoredResource) {
482481
// Read input Resource proto.
483-
f, err := ioutil.ReadFile("testdata/" + filename + "/in.txt")
482+
f, err := readFile("testdata/" + filename + "/in.txt")
484483
if err != nil {
485484
t.Fatalf("error opening in file " + filename)
486485
}
@@ -497,7 +496,7 @@ func readTestResourcesFiles(t *testing.T, filename string) ([]*resourcepb.Resour
497496
}
498497

499498
// Read output Resource proto.
500-
f, err = ioutil.ReadFile("testdata/" + filename + "/out.txt")
499+
f, err = readFile("testdata/" + filename + "/out.txt")
501500
if err != nil {
502501
t.Fatalf("error opening out file " + filename)
503502
}

util_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package stackdriver_test
16+
17+
import (
18+
"io/ioutil"
19+
)
20+
21+
// readFile is a wrapper to read a file. It is meant for internal use for testing.
22+
func readFile(filename string) ([]byte, error) {
23+
return ioutil.ReadFile(filename)
24+
}

0 commit comments

Comments
 (0)