Skip to content

Commit befad4a

Browse files
authored
fix(librarian/rust): install handles nil tools (#5199)
Running `librarian install` in `google-cloud-rust` today panics b.c the `librarian.yaml` hasn't been updated to move `release.tools.cargo` to `tools.cargo` (see #5160).
1 parent acf8cb1 commit befad4a

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

internal/librarian/rust/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var ErrMissingToolVersion = errors.New("cargo tool missing version")
2828

2929
// Install installs cargo tool dependencies defined in the tools configuration.
3030
func Install(ctx context.Context, tools *config.Tools) error {
31-
if len(tools.Cargo) == 0 {
31+
if tools == nil || len(tools.Cargo) == 0 {
3232
return nil
3333
}
3434
for _, tool := range tools.Cargo {

internal/librarian/rust/install_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ func TestInstall_MissingVersion(t *testing.T) {
5454
}
5555

5656
func TestInstall_NoCargoTools(t *testing.T) {
57-
if err := Install(t.Context(), &config.Tools{}); err != nil {
58-
t.Fatal(err)
57+
for _, test := range []struct {
58+
name string
59+
tools *config.Tools
60+
}{
61+
{
62+
name: "nil tools",
63+
},
64+
{
65+
name: "no Cargo tools",
66+
tools: &config.Tools{},
67+
},
68+
} {
69+
t.Run(test.name, func(t *testing.T) {
70+
if err := Install(t.Context(), test.tools); err != nil {
71+
t.Fatal(err)
72+
}
73+
})
5974
}
6075
}

0 commit comments

Comments
 (0)