MCPcopy Create free account
hub / github.com/goadesign/goa / TestProtoc

Function TestProtoc

grpc/codegen/proto_test.go:92–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

90}
91
92func TestProtoc(t *testing.T) {
93 const code = testdata.UnaryRPCsProtoCode
94
95 fakeBin := filepath.Join(os.TempDir(), t.Name()+"-fakeprotoc")
96 if runtime.GOOS == "windows" {
97 fakeBin += ".exe"
98 }
99 out, err := exec.Command("go", "build", "-o", fakeBin, "./testdata/protoc").CombinedOutput()
100 t.Log("go build output: ", string(out))
101 require.NoError(t, err, "compile a fake protoc that requires a prefix")
102 t.Cleanup(func() { assert.NoError(t, os.Remove(fakeBin)) })
103
104 cases := []struct {
105 Name string
106 Cmd []string
107 }{
108 {"protoc", defaultProtocCmd},
109 {"fakepc", []string{fakeBin, "required-ignored-arg"}},
110 }
111
112 var firstOutput string
113
114 for _, c := range cases {
115 t.Run(c.Name, func(t *testing.T) {
116 dir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), "/", "-"))
117 require.NoError(t, err)
118 t.Cleanup(func() { assert.NoError(t, os.RemoveAll(dir)) })
119 fpath := filepath.Join(dir, "schema")
120 require.NoError(t, os.WriteFile(fpath, []byte(code), 0o600), "error occurred writing proto schema")
121 require.NoError(t, protoc(c.Cmd, fpath, nil), "error occurred when compiling proto file with the standard protoc %q", fpath)
122
123 fcontents, err := os.ReadFile(fpath + ".pb.go")
124 require.NoError(t, err)
125
126 if firstOutput == "" {
127 firstOutput = string(fcontents)
128 return
129 }
130
131 assert.Equal(t, firstOutput, string(fcontents))
132 })
133 }
134}

Callers

nothing calls this directly

Calls 6

protocFunction · 0.85
CleanupMethod · 0.80
RemoveMethod · 0.80
NameMethod · 0.65
LogMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected