Skip to content

Commit fe014a9

Browse files
brettfoCopilot
andauthored
Accept hyphenated experiment name and limit case-insensitive filesystem to nuget (#634)
* Accept hyphenated experiment name for case-insensitive filesystem Add experimentEnabled helper that checks both the underscore and hyphenated variants of an experiment name, and use it for the use_case_insensitive_filesystem experiment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Limit case-insensitive filesystem to nuget package manager UseCaseInsensitiveFileSystem now returns true only when the package manager is nuget and the experiment is enabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c95a632 commit fe014a9

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

internal/model/job.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package model
33
import (
44
"encoding/json"
55
"fmt"
6+
"strings"
67
"time"
78
)
89

@@ -62,8 +63,18 @@ type Job struct {
6263
}
6364

6465
func (j *Job) UseCaseInsensitiveFileSystem() bool {
65-
if experimentValue, isBoolean := j.Experiments["use_case_insensitive_filesystem"].(bool); isBoolean && experimentValue {
66-
return true
66+
return j.PackageManager == "nuget" && j.experimentEnabled("use_case_insensitive_filesystem")
67+
}
68+
69+
// experimentEnabled reports whether the named boolean experiment is enabled.
70+
// name is the canonical experiment name using underscores; the hyphenated
71+
// variant is also checked to accommodate both naming conventions.
72+
func (j *Job) experimentEnabled(name string) bool {
73+
hyphenated := strings.ReplaceAll(name, "_", "-")
74+
for _, n := range []string{name, hyphenated} {
75+
if experimentValue, isBoolean := j.Experiments[n].(bool); isBoolean && experimentValue {
76+
return true
77+
}
6778
}
6879

6980
return false

internal/model/job_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,35 @@ func TestInput(t *testing.T) {
2121
compareMap(t, "job", input2["job"], input.Job)
2222
}
2323

24+
func TestUseCaseInsensitiveFileSystem(t *testing.T) {
25+
tests := []struct {
26+
name string
27+
packageManager string
28+
experiments Experiment
29+
want bool
30+
}{
31+
{"nil experiments", "nuget", nil, false},
32+
{"empty experiments", "nuget", Experiment{}, false},
33+
{"underscore true", "nuget", Experiment{"use_case_insensitive_filesystem": true}, true},
34+
{"underscore false", "nuget", Experiment{"use_case_insensitive_filesystem": false}, false},
35+
{"hyphen true", "nuget", Experiment{"use-case-insensitive-filesystem": true}, true},
36+
{"hyphen false", "nuget", Experiment{"use-case-insensitive-filesystem": false}, false},
37+
{"non-bool value", "nuget", Experiment{"use_case_insensitive_filesystem": "true"}, false},
38+
{"non-nuget with experiment", "npm_and_yarn", Experiment{"use_case_insensitive_filesystem": true}, false},
39+
{"non-nuget hyphen with experiment", "gomod", Experiment{"use-case-insensitive-filesystem": true}, false},
40+
{"empty package manager with experiment", "", Experiment{"use_case_insensitive_filesystem": true}, false},
41+
}
42+
43+
for _, tt := range tests {
44+
t.Run(tt.name, func(t *testing.T) {
45+
j := &Job{PackageManager: tt.packageManager, Experiments: tt.experiments}
46+
if got := j.UseCaseInsensitiveFileSystem(); got != tt.want {
47+
t.Errorf("UseCaseInsensitiveFileSystem() = %v, want %v", got, tt.want)
48+
}
49+
})
50+
}
51+
}
52+
2453
func TestAllowedUpdateTypes(t *testing.T) {
2554
var input Input
2655
if err := yaml.Unmarshal([]byte(exampleJob), &input); err != nil {

0 commit comments

Comments
 (0)