increase test coverage and fix some minor bugs
parent
723d2e9488
commit
2b68874087
@ -0,0 +1,52 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/url"
|
||||||
|
"testing"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAuth(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "Registry Auth Suite")
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Describe("the auth module", func() {
|
||||||
|
When("getting an auth url", func() {
|
||||||
|
It("should create a valid auth url object based on the challenge header supplied", func() {
|
||||||
|
input := `bearer realm="https://ghcr.io/token",service="ghcr.io",scope="repository:user/image:pull"`
|
||||||
|
expected := &url.URL{
|
||||||
|
Host: "ghcr.io",
|
||||||
|
Scheme: "https",
|
||||||
|
Path: "/token",
|
||||||
|
RawQuery: "scope=repository%3Acontainrrr%2Fwatchtower%3Apull&service=ghcr.io",
|
||||||
|
}
|
||||||
|
res, err := GetAuthURL(input, "containrrr/watchtower")
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res).To(Equal(expected))
|
||||||
|
})
|
||||||
|
It("should create a valid auth url object based on the challenge header supplied", func() {
|
||||||
|
input := `bearer realm="https://ghcr.io/token",service="ghcr.io"`
|
||||||
|
res, err := GetAuthURL(input, "containrrr/watchtower")
|
||||||
|
Expect(err).To(HaveOccurred())
|
||||||
|
Expect(res).To(BeNil())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
When("getting a challenge url", func() {
|
||||||
|
It("should create a valid challenge url object based on the image ref supplied", func() {
|
||||||
|
expected := url.URL{ Host: "ghcr.io", Scheme: "https", Path: "/v2/"}
|
||||||
|
Expect(GetChallengeURL("ghcr.io/containrrr/watchtower:latest")).To(Equal(expected))
|
||||||
|
})
|
||||||
|
It("should assume dockerhub if the image ref is not fully qualified", func() {
|
||||||
|
expected := url.URL{ Host: "index.docker.io", Scheme: "https", Path: "/v2/"}
|
||||||
|
Expect(GetChallengeURL("containrrr/watchtower:latest")).To(Equal(expected))
|
||||||
|
})
|
||||||
|
It("should convert legacy dockerhub hostnames to index.docker.io", func() {
|
||||||
|
expected := url.URL{ Host: "index.docker.io", Scheme: "https", Path: "/v2/"}
|
||||||
|
Expect(GetChallengeURL("docker.io/containrrr/watchtower:latest")).To(Equal(expected))
|
||||||
|
Expect(GetChallengeURL("registry-1.docker.io/containrrr/watchtower:latest")).To(Equal(expected))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,57 @@
|
|||||||
|
package manifest_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/containrrr/watchtower/pkg/registry/manifest"
|
||||||
|
apiTypes "github.com/docker/docker/api/types"
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestManifest(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "Manifest Suite")
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Describe("the manifest module", func() {
|
||||||
|
|
||||||
|
When("building a manifest url", func() {
|
||||||
|
It("should return a valid url given a fully qualified image", func() {
|
||||||
|
expected := "https://ghcr.io/v2/containrrr/watchtower/manifests/latest"
|
||||||
|
imageInfo := apiTypes.ImageInspect{
|
||||||
|
RepoTags: []string {
|
||||||
|
"ghcr.io/containrrr/watchtower:latest",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := manifest.BuildManifestURL(imageInfo)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res).To(Equal(expected))
|
||||||
|
})
|
||||||
|
It("should assume dockerhub for non-qualified images", func() {
|
||||||
|
expected := "https://index.docker.io/v2/containrrr/watchtower/manifests/latest"
|
||||||
|
imageInfo := apiTypes.ImageInspect{
|
||||||
|
RepoTags: []string {
|
||||||
|
"containrrr/watchtower:latest",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := manifest.BuildManifestURL(imageInfo)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res).To(Equal(expected))
|
||||||
|
})
|
||||||
|
It("should assume latest for images that lack an explicit tag", func() {
|
||||||
|
expected := "https://index.docker.io/v2/containrrr/watchtower/manifests/latest"
|
||||||
|
imageInfo := apiTypes.ImageInspect{
|
||||||
|
RepoTags: []string {
|
||||||
|
"containrrr/watchtower",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := manifest.BuildManifestURL(imageInfo)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res).To(Equal(expected))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
Loading…
Reference in New Issue