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

Commit

Permalink
add wrapper around ioutil.ReadFile. (#226)
Browse files Browse the repository at this point in the history
* add wrapper around ioutil.ReadFile.

* rename ReadFromFile to ReadFile

* refactor interna/ioutil_wrapper.go to util_test.go
  • Loading branch information
rghetia committed Sep 19, 2019
1 parent 3504ffa commit 9cc5395
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
11 changes: 5 additions & 6 deletions metrics_proto_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package stackdriver_test
import (
"context"
"fmt"
"io/ioutil"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -427,7 +426,7 @@ func readTestCaseFromFiles(t *testing.T, filename string) *testCases {
}

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

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

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

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

// Read output Resource proto.
f, err = ioutil.ReadFile("testdata/" + filename + "/out.txt")
f, err = readFile("testdata/" + filename + "/out.txt")
if err != nil {
t.Fatalf("error opening out file " + filename)
}
Expand Down
24 changes: 24 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2019, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package stackdriver_test

import (
"io/ioutil"
)

// readFile is a wrapper to read a file. It is meant for internal use for testing.
func readFile(filename string) ([]byte, error) {
return ioutil.ReadFile(filename)
}

0 comments on commit 9cc5395

Please sign in to comment.