Skip to content

Commit 6356280

Browse files
authored
refactor(sidekick): move rustBumpVersions() (#2128)
Moving the implementation of `rustBumpVersions()` will make it easier to share test code. I will need helpers to simulate a git repository and I would rather keep those in a single package.
1 parent abef71a commit 6356280

File tree

5 files changed

+79
-32
lines changed

5 files changed

+79
-32
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 rustrelease
16+
17+
import "github.com/googleapis/librarian/internal/sidekick/internal/config"
18+
19+
// BumpVersions finds all the crates that need a version bump and performs the
20+
// bump, changing both the Cargo.toml and sidekick.toml files.
21+
func BumpVersions(config *config.Release) error {
22+
if err := PreFlight(config); err != nil {
23+
return err
24+
}
25+
return nil
26+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 rustrelease
16+
17+
import (
18+
"testing"
19+
20+
"github.com/googleapis/librarian/internal/sidekick/internal/config"
21+
)
22+
23+
func TestBumpVersionsSuccess(t *testing.T) {
24+
requireCommand(t, "git")
25+
config := &config.Release{
26+
Preinstalled: map[string]string{
27+
"git": "git",
28+
"cargo": "git",
29+
},
30+
}
31+
if err := BumpVersions(config); err != nil {
32+
t.Fatal(err)
33+
}
34+
}
35+
36+
func TestBumpVersionsPreflightError(t *testing.T) {
37+
config := &config.Release{
38+
Preinstalled: map[string]string{
39+
"git": "git-not-found",
40+
},
41+
}
42+
if err := BumpVersions(config); err == nil {
43+
t.Errorf("expected an error in BumpVersions() with a bad git command")
44+
}
45+
}

internal/sidekick/rust_bump_versions.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ effect.
3636
)
3737
}
3838

39-
// rustGenerate increments the version numbers as needed.
39+
// rustBumpVersions increments the version numbers as needed.
4040
func rustBumpVersions(rootConfig *config.Config, cmdLine *CommandLine) error {
41-
if err := rustrelease.PreFlight(rootConfig.Release); err != nil {
42-
return err
43-
}
44-
return nil
41+
return rustrelease.BumpVersions(rootConfig.Release)
4542
}

internal/sidekick/rust_bump_version_test.go renamed to internal/sidekick/rust_bump_versions_test.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,16 @@ import (
2020
"github.com/googleapis/librarian/internal/sidekick/internal/config"
2121
)
2222

23-
func TestPreflightSuccess(t *testing.T) {
24-
requireGit(t)
25-
config := config.Config{
23+
func TestRustBumpVersions(t *testing.T) {
24+
config := &config.Config{
2625
Release: &config.Release{
2726
Preinstalled: map[string]string{
28-
"git": "git",
29-
"cargo": "git",
27+
"git": "git-not-found",
3028
},
3129
},
3230
}
33-
cmdLine := CommandLine{}
34-
if err := rustBumpVersions(&config, &cmdLine); err != nil {
35-
t.Fatal(err)
36-
}
37-
}
38-
39-
func TestPreflightMissingCommand(t *testing.T) {
40-
requireGit(t)
41-
config := config.Config{
42-
Release: &config.Release{
43-
Preinstalled: map[string]string{
44-
"cargo": "not-a-valid-command-bad-bad",
45-
},
46-
},
47-
}
48-
cmdLine := CommandLine{}
49-
if err := rustBumpVersions(&config, &cmdLine); err == nil {
50-
t.Errorf("expected an error in rustBumpVersions() with a bad cargo command")
31+
cmdLine := &CommandLine{}
32+
if err := rustBumpVersions(config, cmdLine); err == nil {
33+
t.Errorf("expected an error with invalid git command")
5134
}
5235
}

internal/sidekick/sidekick_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,3 @@ func requireProtoc(t *testing.T) {
4949
func requireCargo(t *testing.T) {
5050
requireCommand(t, "cargo")
5151
}
52-
53-
func requireGit(t *testing.T) {
54-
requireCommand(t, "git")
55-
}

0 commit comments

Comments
 (0)