Skip to content

Commit 348290a

Browse files
authored
test(sidekick): missing codec_sample tests (#1629)
1 parent 9fd1850 commit 348290a

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
package codec_sample
16+
17+
import (
18+
"os"
19+
"os/exec"
20+
"path"
21+
"path/filepath"
22+
"testing"
23+
24+
"github.com/googleapis/librarian/internal/sidekick/internal/config"
25+
"github.com/googleapis/librarian/internal/sidekick/internal/parser"
26+
)
27+
28+
var (
29+
testdataDir, _ = filepath.Abs("../../testdata")
30+
)
31+
32+
func TestFromProtobuf(t *testing.T) {
33+
if _, err := exec.LookPath("protoc"); err != nil {
34+
t.Skip("skipping test because protoc is not installed")
35+
}
36+
outDir := t.TempDir()
37+
38+
cfg := &config.Config{
39+
General: config.GeneralConfig{
40+
SpecificationFormat: "protobuf",
41+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
42+
SpecificationSource: "google/cloud/secretmanager/v1",
43+
},
44+
Source: map[string]string{
45+
"googleapis-root": path.Join(testdataDir, "googleapis"),
46+
},
47+
Codec: map[string]string{
48+
"copyright-year": "2025",
49+
"not-for-publication": "true",
50+
"version": "0.1.0",
51+
"skip-format": "true",
52+
"proto:google.protobuf": "package:google_cloud_protobuf/protobuf.dart",
53+
"proto:google.cloud.location": "package:google_cloud_location/location.dart",
54+
},
55+
}
56+
model, err := parser.CreateModel(cfg)
57+
if err != nil {
58+
t.Fatal(err)
59+
}
60+
if err := Generate(model, outDir, cfg); err != nil {
61+
t.Fatal(err)
62+
}
63+
filename := path.Join(outDir, "README.md")
64+
stat, err := os.Stat(filename)
65+
if os.IsNotExist(err) {
66+
t.Errorf("missing %s: %s", filename, err)
67+
}
68+
if stat.Mode().Perm()|0666 != 0666 {
69+
t.Errorf("generated files should not be executable %s: %o", filename, stat.Mode())
70+
}
71+
}

0 commit comments

Comments
 (0)