Skip to content

Commit

Permalink
chore(internal): add sample.SnippetsDirectory (#1518)
Browse files Browse the repository at this point in the history
Add SnippetsDirectory to internal/testing/sample, and use it in tests
where that string is currently hardcoded.
  • Loading branch information
julieqiu committed May 14, 2024
1 parent 08f1371 commit a413e5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/gengapic/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func TestGenSnippetFile(t *testing.T) {
if err != nil {
t.Fatal(err)
}
g.commit(filepath.Join("cloud.google.com/go", "internal", "generated", "snippets", sample.GoPackageName, "main.go"), "main")
g.commit(filepath.Join(sample.SnippetsDirectory, "main.go"), "main")
if diff := cmp.Diff(test.imports, g.imports); diff != "" {
t.Errorf("TestExample(%s) imports mismatch: (-want +got):\n%s", test.name, diff)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/gengapic/snippets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/googleapis/gapic-generator-go/internal/pbinfo"
"github.com/googleapis/gapic-generator-go/internal/snippets"
"github.com/googleapis/gapic-generator-go/internal/testing/sample"
"github.com/googleapis/gapic-generator-go/internal/txtdiff"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/descriptorpb"
Expand All @@ -34,10 +35,10 @@ func TestSnippetsOutDir(t *testing.T) {
}{
{
opts: options{
outDir: "cloud.google.com/go/video/stitcher/apiv1",
pkgPath: "cloud.google.com/go/video/stitcher/apiv1",
outDir: sample.GoPackagePath,
pkgPath: sample.GoPackagePath,
},
want: "cloud.google.com/go/internal/generated/snippets/video/stitcher/apiv1",
want: sample.SnippetsDirectory,
},
{
opts: options{
Expand Down
8 changes: 8 additions & 0 deletions internal/testing/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ const (
GoVersion = "apiv1"
)

const (
// SnippetsDirectory is the directory path containing generated snippets.
//
// Example:
// https://github.com/googleapis/google-cloud-go/tree/main/internal/generated/snippets/secretmanager/apiv1
SnippetsDirectory = "cloud.google.com/go/internal/generated/snippets/secretmanager/apiv1"
)

// DescriptorInfoTypeName constructs the name format used by g.descInfo.Type.
func DescriptorInfoTypeName(typ string) string {
return fmt.Sprintf(".%s.%s", ProtoPackagePath, typ)
Expand Down

0 comments on commit a413e5d

Please sign in to comment.