mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-13 21:56:38 +01:00
feat: make head pull failure warning toggleable (#912)
* feat: make head pull failure warning toggleable * expect prometheus tests to go through EVENTUALLY * wait for queue to be empty before checking test conditions * clean up new head failure toggle * fixup! clean up new head failure toggle * test: add registry tests * test: add warn on head failure tests * fix client interface and make tests hit more lines * make all tests use NewClient instead of creating a struct pointer * fix lint issues Co-authored-by: Simon Aronsson <simme@arcticbit.se>
This commit is contained in:
parent
23572add74
commit
b4cf17d33f
13 changed files with 148 additions and 647 deletions
|
|
@ -95,7 +95,11 @@ func GetDigest(url string, token string) (string, error) {
|
|||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
return "", fmt.Errorf("registry responded to head request with %v", res)
|
||||
wwwAuthHeader := res.Header.Get("www-authenticate")
|
||||
if wwwAuthHeader == "" {
|
||||
wwwAuthHeader = "not present"
|
||||
}
|
||||
return "", fmt.Errorf("registry responded to head request with %q, auth: %q", res.Status, wwwAuthHeader)
|
||||
}
|
||||
return res.Header.Get(ContentDigestHeader), nil
|
||||
}
|
||||
|
|
|
|||
13
pkg/registry/registry_suite_test.go
Normal file
13
pkg/registry/registry_suite_test.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package registry_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestRegistry(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Registry Suite")
|
||||
}
|
||||
45
pkg/registry/registry_test.go
Normal file
45
pkg/registry/registry_test.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package registry_test
|
||||
|
||||
import (
|
||||
"github.com/containrrr/watchtower/internal/actions/mocks"
|
||||
unit "github.com/containrrr/watchtower/pkg/registry"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "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() {
|
||||
Expect(testContainerWithImage("ghcr.io/containrrr/watchtower")).To(BeTrue())
|
||||
})
|
||||
})
|
||||
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("registry-1.docker.io/docker:latest")).To(BeTrue())
|
||||
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)
|
||||
}
|
||||
|
|
@ -4,14 +4,8 @@ import (
|
|||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTrust(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Trust Suite")
|
||||
}
|
||||
|
||||
var _ = Describe("Testing with Ginkgo", func() {
|
||||
It("encoded env auth_ should return an error if repo envs are unset", func() {
|
||||
_ = os.Unsetenv("REPO_USER")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue