Skip to content

Commit

Permalink
fix(ci): lint failed
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackHole1 committed Oct 25, 2023
1 parent 8ff7dbd commit 90692ab
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/rest/vf/vm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package rest

import (
"net/http"
"strings"

"github.com/Code-Hex/vz/v3"
"github.com/crc-org/vfkit/pkg/rest/define"
"github.com/crc-org/vfkit/pkg/util"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -72,7 +72,7 @@ func (vm *VzVirtualMachine) CanOperate(c *gin.Context) {
return
}

can, err := vm.CanChangeState(define.StateChange(strings.Title(p.Op)))
can, err := vm.CanChangeState(define.StateChange(util.FirstUpper(p.Op)))
if err != nil {
logrus.Errorf("failed to check operation %s: %q", p.Op, err)
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
Expand Down
7 changes: 7 additions & 0 deletions pkg/util/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ func StringInSlice(st string, sl []string) bool {
}
return false
}

func FirstUpper(s string) string {
if s == "" {
return ""
}
return strings.ToUpper(s[:1]) + s[1:]
}
40 changes: 40 additions & 0 deletions pkg/util/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,43 @@ func TestTrimQuotes(t *testing.T) {
})
}
}

func TestFirstUpper(t *testing.T) {
tests := []struct {
value string
want string
}{
{
value: "foobar",
want: "Foobar",
},
{
value: "Foobar",
want: "Foobar",
},
{
value: "",
want: "",
},
{
value: "f",
want: "F",
},
{
value: "F",
want: "F",
},
{
value: "1",
want: "1",
},
}

for _, tt := range tests {
t.Run(tt.value, func(t *testing.T) {
if got := FirstUpper(tt.value); got != tt.want {
t.Errorf("FirstUpper() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 90692ab

Please sign in to comment.