Skip to content

Commit

Permalink
update go-format
Browse files Browse the repository at this point in the history
Signed-off-by: Paco Xu <[email protected]>
  • Loading branch information
pacoxu committed Jan 11, 2023
1 parent d24a9dd commit c2b6b14
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion hack/verify-boilerplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func verifyBoilerplate(contents string) error {
return fmt.Errorf("copyright line should contain exactly %d words", expectedLen)
}
if !yearRegexp.MatchString(yearWords[1]) {
return fmt.Errorf("cannot parse the year in the copyright line")
return errors.New("cannot parse the year in the copyright line")
}
bpLine = strings.ReplaceAll(bpLine, yearPlaceholder, yearWords[1])
}
Expand Down
3 changes: 2 additions & 1 deletion validators/cgroup_validator_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

/*
Expand Down Expand Up @@ -69,7 +70,7 @@ func (c *CgroupsValidator) Validate(spec SysSpec) (warns, errs []error) {
} else {
subsystems, err = c.getCgroupV1Subsystems()
if err != nil {
return nil, []error{fmt.Errorf("failed to get cgroup v1 subsystems: %vs", err)}
return nil, []error{fmt.Errorf("failed to get cgroup v1 subsystems: %w", err)}
}
requiredCgroupSpec = spec.Cgroups
optionalCgroupSpec = spec.CgroupsOptional
Expand Down
2 changes: 1 addition & 1 deletion validators/docker_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (d *DockerValidator) Validate(spec SysSpec) ([]error, []error) {

func (d *DockerValidator) unmarshalDockerInfo(b []byte, info *dockerInfo) error {
if err := json.Unmarshal(b, &info); err != nil {
return fmt.Errorf("could not unmarshal the JSON output of 'docker info':\n%q\n err: %w", b, err)
return fmt.Errorf("could not unmarshal the JSON output of 'docker info':\n%s\n err: %w", b, err)
}
return nil
}
Expand Down
14 changes: 8 additions & 6 deletions validators/package_validator_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
package system

import (
"errors"
"fmt"
"io/ioutil"
"os/exec"
Expand All @@ -45,7 +46,7 @@ func newPackageManager() (packageManager, error) {
if m, ok := newDPKG(); ok {
return m, nil
}
return nil, fmt.Errorf("failed to find package manager")
return nil, errors.New("failed to find package manager")
}

// dpkg implements packageManager. It uses "dpkg-query" to retrieve package
Expand All @@ -71,7 +72,7 @@ func (dpkg) getPackageVersion(packageName string) (string, error) {
}
version := extractUpstreamVersion(string(output))
if version == "" {
return "", fmt.Errorf("no version information")
return "", errors.New("no version information")
}
return version, nil
}
Expand Down Expand Up @@ -243,10 +244,11 @@ func extractUpstreamVersion(version string) string {
}

// toSemVerRange converts the input to a semantic version range.
// E.g., ">=1.0" -> ">=1.0.x"
// ">=1" -> ">=1.x"
// ">=1 <=2.3" -> ">=1.x <=2.3.x"
// ">1 || >3.1.0 !4.2" -> ">1.x || >3.1.0 !4.2.x"
// E.g.,
// - ">=1.0" -> ">=1.0.x"
// - ">=1" -> ">=1.x"
// - ">=1 <=2.3" -> ">=1.x <=2.3.x"
// - ">1 || >3.1.0 !4.2" -> ">1.x || >3.1.0 !4.2.x"
func toSemVerRange(input string) string {
var output []string
fields := strings.Fields(input)
Expand Down
5 changes: 3 additions & 2 deletions validators/package_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
package system

import (
"errors"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -202,7 +203,7 @@ func TestValidatePackageVersion(t *testing.T) {
{Name: "bar", VersionRange: ">=3.0"},
},
errs: []error{
fmt.Errorf("package \"bar 2.1.0\" does not meet the spec \"bar (>=3.0)\""),
errors.New("package \"bar 2.1.0\" does not meet the spec \"bar (>=3.0)\""),
},
},
{
Expand All @@ -211,7 +212,7 @@ func TestValidatePackageVersion(t *testing.T) {
{Name: "baz"},
},
errs: []error{
fmt.Errorf("package \"baz\" does not exist"),
errors.New("package \"baz\" does not exist"),
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion validators/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package system

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (dr *StreamReporter) Report(key, value string, resultType ValidationResultT
c = white
}
if dr.WriteStream == nil {
return fmt.Errorf("WriteStream has to be defined for this reporter")
return errors.New("WriteStream has to be defined for this reporter")
}

fmt.Fprintf(dr.WriteStream, "%s: %s\n", colorize(key, white), colorize(value, c))
Expand Down
4 changes: 2 additions & 2 deletions validators/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type KernelConfig struct {

// KernelSpec defines the specification for the kernel. Currently, it contains
// specification for:
// * Kernel Version
// * Kernel Configuration
// - Kernel Version
// - Kernel Configuration
type KernelSpec struct {
// Versions define supported kernel version. It is a group of regexps.
Versions []string `json:"versions,omitempty"`
Expand Down

0 comments on commit c2b6b14

Please sign in to comment.