Skip to content

Commit

Permalink
Fix bug where protobuf was unmarshaled with json.Unmarshal (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
shifucun authored Aug 21, 2020
1 parent dc03933 commit 06db58c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions e2etest/get_stat_series_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package e2etest

import (
"context"
"encoding/json"
"io/ioutil"
"path"
"runtime"
Expand All @@ -25,6 +24,7 @@ import (
pb "github.com/datacommonsorg/mixer/proto"
"github.com/datacommonsorg/mixer/server"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/testing/protocmp"
)

Expand Down Expand Up @@ -114,9 +114,9 @@ func TestGetStatSeries(t *testing.T) {
updateGolden(resp, goldenFile)
continue
}
var expected *pb.GetStatSeriesResponse
var expected pb.GetStatSeriesResponse
file, _ := ioutil.ReadFile(goldenFile)
err = json.Unmarshal(file, &expected)
err = protojson.Unmarshal(file, &expected)
if err != nil {
t.Errorf("Can not Unmarshal golden file")
continue
Expand Down
6 changes: 3 additions & 3 deletions e2etest/get_stat_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package e2etest

import (
"context"
"encoding/json"
"io/ioutil"
"path"
"runtime"
Expand All @@ -25,6 +24,7 @@ import (
pb "github.com/datacommonsorg/mixer/proto"
"github.com/datacommonsorg/mixer/server"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/testing/protocmp"
)

Expand Down Expand Up @@ -121,9 +121,9 @@ func TestGetStatValue(t *testing.T) {
updateGolden(resp, goldenFile)
continue
}
var expected *pb.GetStatValueResponse
var expected pb.GetStatValueResponse
file, _ := ioutil.ReadFile(goldenFile)
err = json.Unmarshal(file, &expected)
err = protojson.Unmarshal(file, &expected)
if err != nil {
t.Errorf("Can not Unmarshal golden file")
continue
Expand Down
4 changes: 2 additions & 2 deletions e2etest/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package e2etest

import (
"context"
"encoding/json"
"io/ioutil"
"path"
"runtime"
Expand All @@ -25,6 +24,7 @@ import (
pb "github.com/datacommonsorg/mixer/proto"
"github.com/datacommonsorg/mixer/server"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/testing/protocmp"
)

Expand Down Expand Up @@ -115,7 +115,7 @@ func TestQuery(t *testing.T) {

var expected pb.QueryResponse
file, _ := ioutil.ReadFile(goldenFile)
if err := json.Unmarshal(file, &expected); err != nil {
if err := protojson.Unmarshal(file, &expected); err != nil {
t.Errorf("Can not Unmarshal golden file %s: %v", c.goldenFile, err)
continue
}
Expand Down

0 comments on commit 06db58c

Please sign in to comment.