2021-04-23 16:34:21 +02:00
|
|
|
package registry_test
|
|
|
|
|
|
|
|
|
|
import (
|
2023-10-04 12:17:38 +02:00
|
|
|
"github.com/nicholas-fedor/watchtower/internal/actions/mocks"
|
|
|
|
|
unit "github.com/nicholas-fedor/watchtower/pkg/registry"
|
2025-02-01 08:00:02 -07:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2021-04-23 16:34:21 +02:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ = Describe("Registry", func() {
|
|
|
|
|
Describe("WarnOnAPIConsumption", func() {
|
|
|
|
|
When("Given a container with an image from ghcr.io", func() {
|
|
|
|
|
It("should want to warn", func() {
|
2023-10-04 12:17:38 +02:00
|
|
|
Expect(testContainerWithImage("ghcr.io/nicholas-fedor/watchtower")).To(BeTrue())
|
2021-04-23 16:34:21 +02:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
When("Given a container with an image implicitly from dockerhub", func() {
|
|
|
|
|
It("should want to warn", func() {
|
|
|
|
|
Expect(testContainerWithImage("docker:latest")).To(BeTrue())
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
When("Given a container with an image explicitly from dockerhub", func() {
|
|
|
|
|
It("should want to warn", func() {
|
|
|
|
|
Expect(testContainerWithImage("index.docker.io/docker:latest")).To(BeTrue())
|
|
|
|
|
Expect(testContainerWithImage("docker.io/docker:latest")).To(BeTrue())
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
When("Given a container with an image from some other registry", func() {
|
|
|
|
|
It("should not want to warn", func() {
|
|
|
|
|
Expect(testContainerWithImage("docker.fsf.org/docker:latest")).To(BeFalse())
|
|
|
|
|
Expect(testContainerWithImage("altavista.com/docker:latest")).To(BeFalse())
|
|
|
|
|
Expect(testContainerWithImage("gitlab.com/docker:latest")).To(BeFalse())
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
func testContainerWithImage(imageName string) bool {
|
|
|
|
|
container := mocks.CreateMockContainer("", "", imageName, time.Now())
|
|
|
|
|
return unit.WarnOnAPIConsumption(container)
|
|
|
|
|
}
|