Skip to content

Commit

Permalink
Switch all calls of assert.Nil to assert.NoError
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Jan 8, 2025
1 parent 2260a34 commit c6e4cb5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cmd/podman/common/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestPodOptions(t *testing.T) {

podOptions := entities.PodCreateOptions{}
err := common.ContainerToPodOptions(&exampleOptions, &podOptions)
assert.Nil(t, err)
assert.NoError(t, err)

cc := reflect.ValueOf(&exampleOptions).Elem()
pc := reflect.ValueOf(&podOptions).Elem()
Expand Down
34 changes: 17 additions & 17 deletions cmd/quadlet/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func TestIsUnambiguousName(t *testing.T) {

func TestUnitDirs(t *testing.T) {
u, err := user.Current()
assert.Nil(t, err)
assert.NoError(t, err)
uidInt, err := strconv.Atoi(u.Uid)
assert.Nil(t, err)
assert.NoError(t, err)

if os.Getenv("_UNSHARED") != "true" {
unitDirs := getUnitDirs(false)
Expand All @@ -71,7 +71,7 @@ func TestUnitDirs(t *testing.T) {
assert.Equal(t, rootfulPaths.sorted, unitDirs, "rootful unit dirs should match")

configDir, err := os.UserConfigDir()
assert.Nil(t, err)
assert.NoError(t, err)

rootlessPaths := newSearchPaths()

Expand Down Expand Up @@ -106,13 +106,13 @@ func TestUnitDirs(t *testing.T) {

actualDir := filepath.Join(symLinkTestBaseDir, "actual")
err = os.Mkdir(actualDir, 0755)
assert.Nil(t, err)
assert.NoError(t, err)
innerDir := filepath.Join(actualDir, "inner")
err = os.Mkdir(innerDir, 0755)
assert.Nil(t, err)
assert.NoError(t, err)
symlink := filepath.Join(symLinkTestBaseDir, "symlink")
err = os.Symlink(actualDir, symlink)
assert.Nil(t, err)
assert.NoError(t, err)
t.Setenv("QUADLET_UNIT_DIRS", symlink)
unitDirs = getUnitDirs(true)
assert.Equal(t, []string{actualDir, innerDir}, unitDirs, "directory resolution should follow symlink")
Expand All @@ -133,15 +133,15 @@ func TestUnitDirs(t *testing.T) {
dirName := filepath.Join(path, name)
assert.NotContains(t, dirs, dirName)
err = os.Mkdir(dirName, 0755)
assert.Nil(t, err)
assert.NoError(t, err)
dirs = append(dirs, dirName)
return dirName, dirs
}

linkDir := func(path, name, target string) {
linkName := filepath.Join(path, name)
err = os.Symlink(target, linkName)
assert.Nil(t, err)
assert.NoError(t, err)
}

symLinkRecursiveTestBaseDir := t.TempDir()
Expand Down Expand Up @@ -199,39 +199,39 @@ func TestUnitDirs(t *testing.T) {
}
c.Env = append(os.Environ(), "_UNSHARED=true")
err = c.Run()
assert.Nil(t, err)
assert.NoError(t, err)
} else {
fmt.Println(os.Args)

symLinkTestBaseDir := t.TempDir()
rootF, err := os.Open("/")
assert.Nil(t, err)
assert.NoError(t, err)
defer rootF.Close()
defer func() {
err := rootF.Chdir()
assert.Nil(t, err)
assert.NoError(t, err)
err = syscall.Chroot(".")
assert.Nil(t, err)
assert.NoError(t, err)
}()
err = syscall.Chroot(symLinkTestBaseDir)
assert.Nil(t, err)
assert.NoError(t, err)

err = os.MkdirAll(quadlet.UnitDirAdmin, 0755)
assert.Nil(t, err)
assert.NoError(t, err)
err = os.RemoveAll(quadlet.UnitDirAdmin)
assert.Nil(t, err)
assert.NoError(t, err)

createDir := func(path, name string) string {
dirName := filepath.Join(path, name)
err = os.Mkdir(dirName, 0755)
assert.Nil(t, err)
assert.NoError(t, err)
return dirName
}

linkDir := func(path, name, target string) {
linkName := filepath.Join(path, name)
err = os.Symlink(target, linkName)
assert.Nil(t, err)
assert.NoError(t, err)
}

systemdDir := createDir("/", "systemd")
Expand Down
10 changes: 5 additions & 5 deletions libpod/container_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestParseOptionIDs(t *testing.T) {
assert.NotNil(t, err)

mappings, err := parseOptionIDs(idMap, "100-200-2")
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, mappings)

assert.Equal(t, len(mappings), 1)
Expand All @@ -43,7 +43,7 @@ func TestParseOptionIDs(t *testing.T) {
assert.Equal(t, mappings[0].Size, 2)

mappings, err = parseOptionIDs(idMap, "100-200-2#300-400-5")
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, mappings)

assert.Equal(t, len(mappings), 2)
Expand All @@ -57,7 +57,7 @@ func TestParseOptionIDs(t *testing.T) {
assert.Equal(t, mappings[1].Size, 5)

mappings, err = parseOptionIDs(idMap, "@100-200-2#@300-400-5")
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, mappings)

assert.Equal(t, len(mappings), 2)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestParseIDMapMountOption(t *testing.T) {
GIDMap: gidMap,
}
uids, gids, err := parseIDMapMountOption(options, "idmap")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, len(uids), 1)
assert.Equal(t, len(gids), 1)

Expand All @@ -110,7 +110,7 @@ func TestParseIDMapMountOption(t *testing.T) {
assert.Equal(t, gids[0].Size, uint32(10000))

uids, gids, err = parseIDMapMountOption(options, "idmap=uids=0-1-10#10-11-10;gids=0-3-10")
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, len(uids), 2)
assert.Equal(t, len(gids), 1)

Expand Down
12 changes: 6 additions & 6 deletions pkg/domain/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,34 @@ func TestParseSCPArgs(t *testing.T) {
var dest *entities.ScpTransferImageOptions
var err error
source, _, err = ParseImageSCPArg(args[0])
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, source.Image, "alpine")

dest, _, err = ParseImageSCPArg(args[1])
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, dest.Image, "")
assert.Equal(t, dest.User, "root")

args = []string{"root@localhost::alpine"}
source, _, err = ParseImageSCPArg(args[0])
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, source.User, "root")
assert.Equal(t, source.Image, "alpine")

args = []string{"charliedoern@192.168.68.126::alpine", "foobar@192.168.68.126::"}
source, _, err = ParseImageSCPArg(args[0])
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, source.Remote)
assert.Equal(t, source.Image, "alpine")

dest, _, err = ParseImageSCPArg(args[1])
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, dest.Remote)
assert.Equal(t, dest.Image, "")

args = []string{"charliedoern@192.168.68.126::alpine"}
source, _, err = ParseImageSCPArg(args[0])
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, source.Remote)
assert.Equal(t, source.Image, "alpine")
}
4 changes: 2 additions & 2 deletions pkg/machine/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
func TestGetSSHIdentityPath(t *testing.T) {
name := "p-test"
datadir, err := env.GetGlobalDataDir()
assert.Nil(t, err)
assert.NoError(t, err)
identityPath, err := env.GetSSHIdentityPath(name)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, identityPath, filepath.Join(datadir, name))
}
8 changes: 4 additions & 4 deletions pkg/machine/provider/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func TestSupportedProviders(t *testing.T) {

func TestInstalledProviders(t *testing.T) {
installed, err := InstalledProviders()
assert.Nil(t, err)
assert.NoError(t, err)
switch runtime.GOOS {
case "darwin":
// TODO: need to verify if an arm64 machine reports {applehv, libkrun}
assert.Equal(t, []define.VMType{define.AppleHvVirt}, installed)
case "windows":
provider, err := Get()
assert.Nil(t, err)
assert.NoError(t, err)
assert.Contains(t, installed, provider)
case "linux":
assert.Equal(t, []define.VMType{define.QemuVirt}, installed)
Expand All @@ -41,7 +41,7 @@ func TestInstalledProviders(t *testing.T) {

func TestHasPermsForProvider(t *testing.T) {
provider, err := Get()
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, HasPermsForProvider(provider.VMType()))
}

Expand Down Expand Up @@ -72,7 +72,7 @@ func TestBadSupportedProviders(t *testing.T) {

func TestBadInstalledProviders(t *testing.T) {
installed, err := InstalledProviders()
assert.Nil(t, err)
assert.NoError(t, err)
switch runtime.GOOS {
case "darwin":
assert.NotEqual(t, []define.VMType{define.QemuVirt}, installed)
Expand Down
2 changes: 1 addition & 1 deletion pkg/specgen/generate/kube/play_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func TestEnvVarValue(t *testing.T) {
stringNumCPUs := strconv.Itoa(runtime.NumCPU())

mi, err := meminfo.Read()
assert.Nil(t, err)
assert.NoError(t, err)
stringMemTotal := strconv.FormatInt(mi.MemTotal, 10)

tests := []struct {
Expand Down
10 changes: 5 additions & 5 deletions pkg/specgenutil/specgenutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestWinPath(t *testing.T) {
assert.NotNil(t, err, msg)
continue
}
if !assert.Nil(t, err, msg) {
if !assert.NoError(t, err, msg) {
continue
}
if test.isN {
Expand All @@ -80,30 +80,30 @@ func TestWinPath(t *testing.T) {

func TestParseLinuxResourcesDeviceAccess(t *testing.T) {
d, err := parseLinuxResourcesDeviceAccess("a *:* rwm")
assert.Nil(t, err, "err is nil")
assert.NoError(t, err, "err is nil")
assert.True(t, d.Allow, "allow is true")
assert.Equal(t, d.Type, "a", "type is 'a'")
assert.Nil(t, d.Minor, "minor is nil")
assert.Nil(t, d.Major, "major is nil")

d, err = parseLinuxResourcesDeviceAccess("b 3:* rwm")
assert.Nil(t, err, "err is nil")
assert.NoError(t, err, "err is nil")
assert.True(t, d.Allow, "allow is true")
assert.Equal(t, d.Type, "b", "type is 'b'")
assert.Nil(t, d.Minor, "minor is nil")
assert.NotNil(t, d.Major, "major is not nil")
assert.Equal(t, *d.Major, int64(3), "major is 3")

d, err = parseLinuxResourcesDeviceAccess("a *:3 rwm")
assert.Nil(t, err, "err is nil")
assert.NoError(t, err, "err is nil")
assert.True(t, d.Allow, "allow is true")
assert.Equal(t, d.Type, "a", "type is 'a'")
assert.Nil(t, d.Major, "major is nil")
assert.NotNil(t, d.Minor, "minor is not nil")
assert.Equal(t, *d.Minor, int64(3), "minor is 3")

d, err = parseLinuxResourcesDeviceAccess("c 1:2 rwm")
assert.Nil(t, err, "err is nil")
assert.NoError(t, err, "err is nil")
assert.True(t, d.Allow, "allow is true")
assert.Equal(t, d.Type, "c", "type is 'c'")
assert.NotNil(t, d.Major, "minor is not nil")
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func TestGetRootlessKeepIDMapping(t *testing.T) {

for _, test := range tests {
options, uid, gid, err := getRootlessKeepIDMapping(test.uid, test.gid, test.uids, test.gids)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, test.expectedOptions, options)
assert.Equal(t, test.expectedUID, uid)
assert.Equal(t, test.expectedGID, gid)
Expand Down Expand Up @@ -756,7 +756,7 @@ func TestProcessOptions(t *testing.T) {
if tt.expectErr {
assert.NotNil(t, err)
} else {
assert.Nil(t, err)
assert.NoError(t, err)
sort.Strings(opts)
sort.Strings(tt.expected)
assert.Equal(t, opts, tt.expected)
Expand Down

0 comments on commit c6e4cb5

Please sign in to comment.