Skip to content

Commit 296ffad

Browse files
committed
test(generator/go) add an integration test for golang generation
1 parent 56c7a5b commit 296ffad

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: "Client Generator: Go"
16+
permissions: read-all
17+
18+
on: [push, pull_request]
19+
20+
jobs:
21+
generator-build:
22+
runs-on: ubuntu-24.04
23+
defaults:
24+
run:
25+
working-directory: generator
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Install protoc
29+
run: |
30+
set -e
31+
curl -fSSL -o /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v28.3/protoc-28.3-linux-x86_64.zip
32+
cd /usr/local
33+
sudo unzip -x /tmp/protoc.zip
34+
protoc --version
35+
- run: go install golang.org/x/tools/cmd/goimports@latest
36+
- name: Setup Go
37+
uses: actions/setup-go@v5
38+
with:
39+
go-version: '1.23'
40+
- run: go get
41+
- run: go test
42+
working-directory: internal/golang
43+
44+
- name: Generate Go API
45+
run: >-
46+
go run cmd/sidekick/main.go generate -project-root=..
47+
-specification-format=openapi
48+
-specification-source=generator/testdata/openapi/secretmanager_openapi_v1.json
49+
-service-config=generator/testdata/googleapis/google/cloud/secretmanager/v1/secretmanager_v1.yaml
50+
-codec-option=go-package-name=secretmanager
51+
-codec-option=package:wkt=package=types,path=types,source=google.protobuf
52+
-codec-option=package:gax=package=gax,path=gax,feature=unstable-sdk-client
53+
-language=go
54+
-output=generator/testdata/go/openapi/golden
55+
56+
# TODO(devoncarew): Commented out as the generated code does not currently build.
57+
# - name: Validate generation
58+
# working-directory: testdata/rust/openapi/golden
59+
# run: go build

generator/internal/golang/golang_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
package golang
1616

1717
import (
18+
"io/fs"
19+
"path/filepath"
20+
"strings"
1821
"testing"
1922

2023
"github.com/google/go-cmp/cmp"
@@ -172,3 +175,22 @@ func TestGo_ValidateMessageMismatch(t *testing.T) {
172175
t.Errorf("expected an error in API validation got=%s", sourceSpecificationPackageName)
173176
}
174177
}
178+
179+
func TestGo_TemplatesAvailable(t *testing.T) {
180+
var count = 0
181+
fs.WalkDir(goTemplates, "templates", func(path string, d fs.DirEntry, err error) error {
182+
if filepath.Ext(path) != ".mustache" {
183+
return nil
184+
}
185+
if strings.Count(d.Name(), ".") == 1 {
186+
// skip partials
187+
return nil
188+
}
189+
count++
190+
return nil
191+
})
192+
193+
if count == 0 {
194+
t.Errorf("no go templates found")
195+
}
196+
}

generator/internal/golang/templates/go.mod.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ limitations under the License.
1616
module {{Codec.PackageName}}
1717

1818
go 1.23.2
19+
20+
require (
21+
cloud.google.com/go/auth v0.14.1 // indirect
22+
cloud.google.com/go/compute/metadata v0.6.0 // indirect
23+
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
24+
golang.org/x/sys v0.29.0 // indirect
25+
)

0 commit comments

Comments
 (0)