Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/librarian/tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,12 @@ func tidyLanguageConfig(lib *config.Library, cfg *config.Config) (*config.Librar

// isToolsEmpty returns true if the tools configuration is empty.
func isToolsEmpty(tools *config.Tools) bool {
return len(tools.Cargo) == 0 && len(tools.PNPM) == 0 && len(tools.Pip) == 0 && len(tools.Go) == 0
return len(tools.Cargo) == 0 &&
len(tools.Go) == 0 &&
len(tools.Maven) == 0 &&
Comment thread
JoeWang1127 marked this conversation as resolved.
len(tools.Pip) == 0 &&
len(tools.PNPM) == 0 &&
tools.Protoc == nil
Comment thread
JoeWang1127 marked this conversation as resolved.
}

// isDefaultEmpty returns true if the default configuration is empty.
Expand Down
46 changes: 36 additions & 10 deletions internal/librarian/tidy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,8 @@ func TestTidy_UnusedSections(t *testing.T) {
for _, test := range []struct {
name string
cfg *config.Config
wantTools bool
wantDefault bool
wantTools *config.Tools
wantDefault *config.Default
}{
{
name: "empty sections removed",
Expand All @@ -738,8 +738,8 @@ func TestTidy_UnusedSections(t *testing.T) {
Tools: &config.Tools{},
Default: &config.Default{},
},
wantTools: false,
wantDefault: false,
wantTools: nil,
wantDefault: nil,
},
{
name: "non-empty sections preserved",
Expand All @@ -751,8 +751,34 @@ func TestTidy_UnusedSections(t *testing.T) {
Tools: &config.Tools{Cargo: []*config.CargoTool{{Name: "taplo", Version: "1.0"}}},
Default: &config.Default{Output: "output"},
},
wantTools: true,
wantDefault: true,
wantTools: &config.Tools{Cargo: []*config.CargoTool{{Name: "taplo", Version: "1.0"}}},
wantDefault: &config.Default{Output: "output"},
},
{
name: "maven preserved",
cfg: &config.Config{
Language: config.LanguageJava,
Sources: &config.Sources{
Googleapis: &config.Source{Commit: "commit"},
},
Tools: &config.Tools{Maven: []*config.MavenTool{{Name: "artifact", Version: "1.2.3"}}},
Default: &config.Default{},
},
wantTools: &config.Tools{Maven: []*config.MavenTool{{Name: "artifact", Version: "1.2.3"}}},
wantDefault: nil,
},
{
name: "protoc preserved",
cfg: &config.Config{
Language: config.LanguageRust,
Sources: &config.Sources{
Googleapis: &config.Source{Commit: "commit"},
},
Tools: &config.Tools{Protoc: &config.Protoc{Version: "33.2", SHA256: "123abc"}},
Default: &config.Default{},
},
wantTools: &config.Tools{Protoc: &config.Protoc{Version: "33.2", SHA256: "123abc"}},
wantDefault: nil,
},
} {
t.Run(test.name, func(t *testing.T) {
Expand All @@ -764,11 +790,11 @@ func TestTidy_UnusedSections(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if (got.Tools != nil) != test.wantTools {
t.Errorf("Tools present = %v, want %v", got.Tools != nil, test.wantTools)
if diff := cmp.Diff(test.wantTools, got.Tools); diff != "" {
t.Errorf("Tools mismatch (-want +got):\n%s", diff)
}
if (got.Default != nil) != test.wantDefault {
t.Errorf("Default present = %v, want %v", got.Default != nil, test.wantDefault)
if diff := cmp.Diff(test.wantDefault, got.Default); diff != "" {
t.Errorf("Default mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down
Loading