-
Notifications
You must be signed in to change notification settings - Fork 847
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve registry ref processing, logging & test files
- Loading branch information
Showing
6 changed files
with
102 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
package registry | ||
|
||
import ( | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"os" | ||
) | ||
|
||
var _ = Describe("Testing with Ginkgo", func() { | ||
It("encoded env auth_ should return an error if repo envs are unset", func() { | ||
_ = os.Unsetenv("REPO_USER") | ||
_ = os.Unsetenv("REPO_PASS") | ||
|
||
_, err := EncodedEnvAuth("") | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
It("encoded env auth_ should return auth hash if repo envs are set", func() { | ||
var err error | ||
expectedHash := "eyJ1c2VybmFtZSI6ImNvbnRhaW5ycnItdXNlciIsInBhc3N3b3JkIjoiY29udGFpbnJyci1wYXNzIn0=" | ||
var _ = Describe("Registry credential helpers", func() { | ||
Describe("EncodedAuth", func() { | ||
It("should return repo credentials from env when set", func() { | ||
var err error | ||
expected := "eyJ1c2VybmFtZSI6ImNvbnRhaW5ycnItdXNlciIsInBhc3N3b3JkIjoiY29udGFpbnJyci1wYXNzIn0=" | ||
|
||
err = os.Setenv("REPO_USER", "containrrr-user") | ||
Expect(err).NotTo(HaveOccurred()) | ||
err = os.Setenv("REPO_USER", "containrrr-user") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = os.Setenv("REPO_PASS", "containrrr-pass") | ||
Expect(err).NotTo(HaveOccurred()) | ||
err = os.Setenv("REPO_PASS", "containrrr-pass") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
config, err := EncodedEnvAuth("") | ||
Expect(config).To(Equal(expectedHash)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
config, err := EncodedEnvAuth() | ||
Expect(config).To(Equal(expected)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
}) | ||
It("encoded config auth_ should return an error if file is not present", func() { | ||
var err error | ||
|
||
err = os.Setenv("DOCKER_CONFIG", "/dev/null/should-fail") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
_, err = EncodedConfigAuth("") | ||
Expect(err).To(HaveOccurred()) | ||
Describe("EncodedEnvAuth", func() { | ||
It("should return an error if repo envs are unset", func() { | ||
_ = os.Unsetenv("REPO_USER") | ||
_ = os.Unsetenv("REPO_PASS") | ||
|
||
_, err := EncodedEnvAuth() | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
}) | ||
/* | ||
* TODO: | ||
* This part only confirms that it still works in the same way as it did | ||
* with the old version of the docker api client sdk. I'd say that | ||
* ParseServerAddress likely needs to be elaborated a bit to default to | ||
* dockerhub in case no server address was provided. | ||
* | ||
* ++ @simskij, 2019-04-04 | ||
*/ | ||
It("parse server address_ should return error if passed empty string", func() { | ||
|
||
_, err := ParseServerAddress("") | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
It("parse server address_ should return the organization part if passed an image name missing server name", func() { | ||
Describe("EncodedConfigAuth", func() { | ||
It("should return an error if file is not present", func() { | ||
var err error | ||
|
||
err = os.Setenv("DOCKER_CONFIG", "/dev/null/should-fail") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
val, _ := ParseServerAddress("containrrr/config") | ||
Expect(val).To(Equal("containrrr")) | ||
_, err = EncodedConfigAuth("") | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
}) | ||
It("parse server address_ should return the server name if passed a fully qualified image name", func() { | ||
|
||
val, _ := ParseServerAddress("github.com/containrrrr/config") | ||
Expect(val).To(Equal("github.com")) | ||
Describe("GetRegistryAddress", func() { | ||
It("should return error if passed empty string", func() { | ||
_, err := GetRegistryAddress("") | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
It("should return docker.io if passed a single-part image name with no explicit domain", func() { | ||
Expect(GetRegistryAddress("containrrr")).To(Equal(DefaultRegistryDomain)) | ||
}) | ||
It("should return the organization part if passed a multi-part image name with no explicit domain", func() { | ||
Expect(GetRegistryAddress("containrrr/config")).To(Equal("containrrr")) | ||
}) | ||
It("should return the server name if passed a fully qualified image name", func() { | ||
Expect(GetRegistryAddress("github.com/containrrr/config")).To(Equal("github.com")) | ||
}) | ||
}) | ||
}) |