From b5b56197b4211a419b41ffb38e6dc5778e8d240d Mon Sep 17 00:00:00 2001 From: Simon Aronsson Date: Thu, 4 Apr 2019 19:55:05 +0200 Subject: [PATCH] add tests to ensure function even after switching docker version --- container/trust_test.go | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 container/trust_test.go diff --git a/container/trust_test.go b/container/trust_test.go new file mode 100644 index 0000000..fc96971 --- /dev/null +++ b/container/trust_test.go @@ -0,0 +1,49 @@ +package container + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_ShouldWork(t *testing.T) { + assert.True(t, true) +} + +func TestEncodedEnvAuth_ShouldReturnAnErrorIfRepoEnvsAreUnset(t *testing.T) { + os.Unsetenv("REPO_USER") + os.Unsetenv("REPO_PASS") + _, err := EncodedEnvAuth("") + assert.Error(t, err) +} +func TestEncodedEnvAuth_ShouldReturnAuthHashIfRepoEnvsAreSet(t *testing.T) { + expectedHash := "eyJ1c2VybmFtZSI6ImNvbnRhaW5ycnItdXNlciIsInBhc3N3b3JkIjoiY29udGFpbnJyci1wYXNzIn0=" + + os.Setenv("REPO_USER", "containrrr-user") + os.Setenv("REPO_PASS", "containrrr-pass") + config, _ := EncodedEnvAuth("") + + assert.Equal(t, config, expectedHash) +} + +func TestEncodedConfigAuth_ShouldReturnAnErrorIfFileIsNotPresent(t *testing.T) { + os.Setenv("DOCKER_CONFIG", "/dev/null/should-fail") + _, err := EncodedConfigAuth("") + assert.Error(t, err) +} + +func TestParseServerAddress_ShouldReturnErrorIfPassedEmptyString(t *testing.T) { + _, err := ParseServerAddress("") + assert.Error(t, err) +} + +func TestParseServerAddress_ShouldReturnTheOrganizationPartIfPassedAnImageNameMissingServerName(t *testing.T) { + val, _ := ParseServerAddress("containrrr/config") + assert.Equal(t, val, "containrrr") +} + +func TestParseServerAddress_ShouldReturnTheRepoNameIfPassedAnImageNameWithoutServerName(t *testing.T) { + val, _ := ParseServerAddress("github.com/containrrrr/config") + assert.Equal(t, val, "github.com") +}