Skip to content

Commit

Permalink
vcsim: Fix PropertyCollector to handle empty property
Browse files Browse the repository at this point in the history
Closes: #3275
Signed-off-by: syuparn <[email protected]>
  • Loading branch information
Syuparn committed Nov 3, 2023
1 parent 35b0fff commit c8a2fc2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions simulator/property_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,16 @@ func toString(v *string) string {
}

func lcFirst(s string) string {
if len(s) < 1 {
return s
}
return strings.ToLower(s[:1]) + s[1:]
}

func ucFirst(s string) string {
if len(s) < 1 {
return s
}
return strings.ToUpper(s[:1]) + s[1:]
}

Expand Down
42 changes: 42 additions & 0 deletions simulator/property_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1709,3 +1709,45 @@ func TestPropertyCollectorNoPathSet(t *testing.T) {
t.Fatalf("len(content)=%d", len(content))
}
}

func TestLcFirst(t *testing.T) {
tests := []struct {
input string
expected string
}{
{input: "ABC", expected: "aBC"},
{input: "abc", expected: "abc"},
{input: "", expected: ""},
}

for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
actual := lcFirst(tt.input)

if actual != tt.expected {
t.Errorf("%q != %q", actual, tt.expected)
}
})
}
}

func TestUcFirst(t *testing.T) {
tests := []struct {
input string
expected string
}{
{input: "ABC", expected: "ABC"},
{input: "abc", expected: "Abc"},
{input: "", expected: ""},
}

for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
actual := ucFirst(tt.input)

if actual != tt.expected {
t.Errorf("%q != %q", actual, tt.expected)
}
})
}
}

0 comments on commit c8a2fc2

Please sign in to comment.