assert => require

This commit is contained in:
Christopher Homberger
2026-02-22 21:00:42 +01:00
parent d187ac2fc1
commit a77f10683d
35 changed files with 228 additions and 200 deletions

View File

@@ -6,6 +6,7 @@ import (
log "github.com/sirupsen/logrus"
assert "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func init() {
@@ -25,7 +26,7 @@ func TestGetSocketAndHostWithSocket(t *testing.T) {
ret, err := GetSocketAndHost(socketURI)
// Assert
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, SocketAndHost{socketURI, dockerHost}, ret)
}
@@ -38,7 +39,7 @@ func TestGetSocketAndHostNoSocket(t *testing.T) {
ret, err := GetSocketAndHost("")
// Assert
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, SocketAndHost{dockerHost, dockerHost}, ret)
}
@@ -53,7 +54,7 @@ func TestGetSocketAndHostOnlySocket(t *testing.T) {
ret, err := GetSocketAndHost(socketURI)
// Assert
assert.NoError(t, err, "Expected no error from GetSocketAndHost")
require.NoError(t, err, "Expected no error from GetSocketAndHost")
assert.True(t, defaultSocketFound, "Expected to find default socket")
assert.Equal(t, socketURI, ret.Socket, "Expected socket to match common location")
assert.Equal(t, defaultSocket, ret.Host, "Expected ret.Host to match default socket location")
@@ -69,7 +70,7 @@ func TestGetSocketAndHostDontMount(t *testing.T) {
ret, err := GetSocketAndHost("-")
// Assert
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, SocketAndHost{"-", dockerHost}, ret)
}
@@ -84,7 +85,7 @@ func TestGetSocketAndHostNoHostNoSocket(t *testing.T) {
// Assert
assert.True(t, found, "Expected a default socket to be found")
assert.NoError(t, err, "Expected no error from GetSocketAndHost")
require.NoError(t, err, "Expected no error from GetSocketAndHost")
assert.Equal(t, SocketAndHost{defaultSocket, defaultSocket}, ret, "Expected to match default socket location")
}
@@ -97,7 +98,7 @@ func TestGetSocketAndHostNoHostNoSocketDefaultLocation(t *testing.T) {
mySocket := mySocketFile.Name()
unixSocket := "unix://" + mySocket
defer os.RemoveAll(mySocket)
assert.NoError(t, tmpErr)
require.NoError(t, tmpErr)
os.Unsetenv("DOCKER_HOST")
CommonSocketLocations = []string{mySocket}
@@ -109,7 +110,7 @@ func TestGetSocketAndHostNoHostNoSocketDefaultLocation(t *testing.T) {
// Assert
assert.Equal(t, unixSocket, defaultSocket, "Expected default socket to match common socket location")
assert.True(t, found, "Expected default socket to be found")
assert.NoError(t, err, "Expected no error from GetSocketAndHost")
require.NoError(t, err, "Expected no error from GetSocketAndHost")
assert.Equal(t, SocketAndHost{unixSocket, unixSocket}, ret, "Expected to match default socket location")
}
@@ -145,6 +146,6 @@ func TestGetSocketAndHostOnlySocketValidButUnusualLocation(t *testing.T) {
assert.Empty(t, defaultSocket, "Expect default socket location to be empty")
assert.False(t, found, "Expected no default socket to be found")
// Sane default
assert.NoError(t, err, "Expect no error from GetSocketAndHost")
require.NoError(t, err, "Expect no error from GetSocketAndHost")
assert.Equal(t, socketURI, ret.Host, "Expect host to default to unusual socket")
}