Show correct container runtime in init logging (#1250)

* Show correct container runtime in init logging

Init logging now logs using container runtime specified by the user instead of always logging "Docker"

Signed-off-by: Thorsten Hans <thorsten.hans@gmail.com>

#1209

* tests: set test name in test data to remove fmt import

Signed-off-by: Thorsten Hans <thorsten.hans@gmail.com>

* remove usage of golang.org/x/text and log container runtime names as they are

Signed-off-by: Thorsten Hans <thorsten.hans@gmail.com>

* ensure modified files do not introduce linting errors

Signed-off-by: Thorsten Hans <thorsten.hans@gmail.com>

---------

Signed-off-by: Thorsten Hans <thorsten.hans@gmail.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
This commit is contained in:
Thorsten Hans 2023-02-28 18:46:25 +01:00 committed by GitHub
parent 211e57b915
commit 06a4c6bddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -164,7 +164,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod
// If --slim installation is not requested, check if docker is installed.
conatinerRuntimeAvailable := utils.IsDockerInstalled() || utils.IsPodmanInstalled()
if !conatinerRuntimeAvailable {
return errors.New("could not connect to Docker. Docker may not be installed or running")
return fmt.Errorf("could not connect to %s. %s may not be installed or running", containerRuntime, containerRuntime)
}
// Initialize default registry only if any of --slim or --image-registry or --from-dir are not given.

View File

@ -18,6 +18,8 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/dapr/cli/utils"
)
func TestStandaloneConfig(t *testing.T) {
@ -310,3 +312,24 @@ func TestIsAirGapInit(t *testing.T) {
})
}
}
func TestInitLogActualContainerRuntimeName(t *testing.T) {
tests := []struct {
containerRuntime string
testName string
}{
{"podman", "Init should log podman as container runtime"},
{"docker", "Init should log docker as container runtime"},
}
conatinerRuntimeAvailable := utils.IsDockerInstalled() || utils.IsPodmanInstalled()
if conatinerRuntimeAvailable {
t.Skip("Skipping test as container runtime is available")
}
for _, test := range tests {
t.Run(test.testName, func(t *testing.T) {
err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "")
assert.NotNil(t, err)
assert.Contains(t, err.Error(), test.containerRuntime)
})
}
}