Skip to content

Commit

Permalink
Change request directory and add test.PathToDir
Browse files Browse the repository at this point in the history
Signed-off-by: Oğuzhan Durgun <[email protected]>
  • Loading branch information
oguzhand95 committed Sep 26, 2023
1 parent cd64941 commit 6343e83
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ go 1.21
require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20230824200731-b9b8148056b9.1
github.com/lyft/protoc-gen-star/v2 v2.0.3
github.com/stretchr/testify v1.8.4
google.golang.org/protobuf v1.31.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/text v0.10.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lyft/protoc-gen-star/v2 v2.0.3 h1:/3+/2sWyXeMLzKd1bX+ixWKgEMsULrIivpDsuaF441o=
github.com/lyft/protoc-gen-star/v2 v2.0.3/go.mod h1:amey7yeodaJhXSbf/TlLvWiqQfLOSpEk//mLlc+axEk=
Expand Down Expand Up @@ -438,6 +440,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
30 changes: 30 additions & 0 deletions internal/module/module_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021-2023 Zenauth Ltd.
// SPDX-License-Identifier: Apache-2.0

package module_test

import (
"bytes"
"os"
"testing"

pgs "github.com/lyft/protoc-gen-star/v2"
"github.com/stretchr/testify/require"

"github.com/cerbos/protoc-gen-jsonschema/internal/common"
"github.com/cerbos/protoc-gen-jsonschema/internal/module"
"github.com/cerbos/protoc-gen-jsonschema/internal/test"
)

const requestName = "code_generator_request.pb.bin"

func TestModule(t *testing.T) {
reqFile, err := os.Open(test.PathToDir(t, requestName))
require.NoError(t, err)
resBytes := &bytes.Buffer{}
pgs.Init(
pgs.DebugEnv(common.DebugEnv),
pgs.ProtocInput(reqFile),
pgs.ProtocOutput(resBytes),
).RegisterModule(module.New()).Render()
}
2 changes: 1 addition & 1 deletion internal/test/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ version: v1
plugins:
- name: debug
out: .
opt: .
opt: testdata
path: ["go", "run", "github.com/lyft/protoc-gen-star/protoc-gen-debug@latest"]
22 changes: 22 additions & 0 deletions internal/test/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021-2023 Zenauth Ltd.
// SPDX-License-Identifier: Apache-2.0

package test

import (
"path/filepath"
"runtime"
"testing"
)

func PathToDir(tb testing.TB, dir string) string {
tb.Helper()

_, currFile, _, ok := runtime.Caller(0)
if !ok {
tb.Error("Failed to detect testdata directory")
return ""
}

return filepath.Join(filepath.Dir(currFile), "testdata", dir)
}
Binary file not shown.

0 comments on commit 6343e83

Please sign in to comment.