Skip to content

Commit

Permalink
Merge pull request #3 from ryoya-fujimoto/fix_bugs20200223
Browse files Browse the repository at this point in the history
Fix bugs20200223
  • Loading branch information
ryoya-fujimoto authored Feb 23, 2020
2 parents ee3f05a + cc0a206 commit fdf6e23
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"text/template"

"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -50,6 +51,11 @@ func Add(c *cli.Context) error {
var base bytes.Buffer
_ = tpl.Execute(&base, m)

err = os.MkdirAll(filepath.Dir(outPath), 0755)
if err != nil {
return err
}

err = ioutil.WriteFile(outPath, base.Bytes(), 0644)
if err != nil {
return err
Expand Down
27 changes: 27 additions & 0 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"reflect"

"github.com/google/go-cmp/cmp"

"github.com/mattn/go-zglob"

"github.com/kylelemons/godebug/pretty"
Expand Down Expand Up @@ -94,6 +96,9 @@ func test(serverHost, testFile, testName string) ([]string, error) {
return nil, err
}

diff := compareResult(expectJSON, resJSON)
fmt.Println("diff:", diff)

if !reflect.DeepEqual(expectJSON, resJSON) {
ej, _ := json.Marshal(expectJSON)
rj, _ := json.Marshal(resJSON)
Expand All @@ -106,3 +111,25 @@ func test(serverHost, testFile, testName string) ([]string, error) {

return errs, nil
}

func compareResult(expect, result map[string]interface{}) string {
mapComparer := cmp.Comparer(func(x, y map[string]interface{}) bool {
for key := range x {
if _, ok := y[key]; !ok {
delete(x, key)
}
}
for key := range y {
if _, ok := x[key]; !ok {
delete(y, key)
}
}

return cmp.Equal(x, y)
})
filter := cmp.FilterValues(func(x, y map[string]interface{}) bool {
return len(x) != len(y)
}, mapComparer)

return cmp.Diff(expect, result, cmp.AllowUnexported(), filter)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
cuelang.org/go v0.0.15
github.com/emicklei/proto v1.9.0
github.com/fullstorydev/grpcurl v1.4.0
github.com/google/go-cmp v0.4.0
github.com/jhump/protoreflect v1.5.0
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-zglob v0.0.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jhump/protoreflect v1.5.0 h1:NgpVT+dX71c8hZnxHof2M7QDK7QtohIJ7DYycjnkyfc=
github.com/jhump/protoreflect v1.5.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
Expand Down Expand Up @@ -98,6 +100,8 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
Expand Down

0 comments on commit fdf6e23

Please sign in to comment.