From 0baaf647f1ccab9f4b3bba724c59afd5f800723e Mon Sep 17 00:00:00 2001 From: jebabin Date: Sat, 9 Sep 2023 16:21:08 +0000 Subject: [PATCH] Add more update test when label take precedence is true. Fix issue in arguments.md --- docs/arguments.md | 5 ++-- internal/actions/update_test.go | 46 ++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/docs/arguments.md b/docs/arguments.md index 61fb3c1..ba538df 100644 --- a/docs/arguments.md +++ b/docs/arguments.md @@ -238,8 +238,7 @@ Environment Variable: WATCHTOWER_MONITOR_ONLY Note that monitor-only can also be specified on a per-container basis with the `com.centurylinklabs.watchtower.monitor-only` label set on those containers. -See [With label taking precedence over arguments](##With label taking precedence over arguments) for behavior when both agument and label are set - +See [With label taking precedence over arguments](#With-label-taking-precedence-over-arguments) for behavior when both argument and label are set ## With label taking precedence over arguments @@ -278,7 +277,7 @@ Environment Variable: WATCHTOWER_NO_PULL Note that no-pull can also be specified on a per-container basis with the `com.centurylinklabs.watchtower.no-pull` label set on those containers. -See [With label taking precedence over arguments](##With label taking precedence over arguments) for behavior when both agument and label are set +See [With label taking precedence over arguments](#With-label-taking-precedence-over-arguments) for behavior when both argument and label are set ## Without sending a startup message Do not send a message after watchtower started. Otherwise there will be an info-level notification. diff --git a/internal/actions/update_test.go b/internal/actions/update_test.go index 03fdfbf..9209dcd 100644 --- a/internal/actions/update_test.go +++ b/internal/actions/update_test.go @@ -182,7 +182,6 @@ var _ = Describe("the update action", func() { Expect(err).NotTo(HaveOccurred()) Expect(client.TestData.TriedToRemoveImageCount).To(Equal(0)) }) - When("watchtower has been instructed to have label take precedence", func() { It("it should update containers when monitor only is set to false", func() { client := CreateMockClient( @@ -210,6 +209,51 @@ var _ = Describe("the update action", func() { Expect(err).NotTo(HaveOccurred()) Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1)) }) + It("it should update not containers when monitor only is set to true", func() { + client := CreateMockClient( + &TestData{ + //NameOfContainerToKeep: "test-container-02", + Containers: []types.Container{ + CreateMockContainerWithConfig( + "test-container-02", + "test-container-02", + "fake-image2:latest", + false, + false, + time.Now(), + &dockerContainer.Config{ + Labels: map[string]string{ + "com.centurylinklabs.watchtower.monitor-only": "true", + }, + }), + }, + }, + false, + false, + ) + _, err := actions.Update(client, types.UpdateParams{Cleanup: true, MonitorOnly: true, LabelPrecedence: true}) + Expect(err).NotTo(HaveOccurred()) + Expect(client.TestData.TriedToRemoveImageCount).To(Equal(0)) + }) + It("it should update not containers when monitor only is not set", func() { + client := CreateMockClient( + &TestData{ + Containers: []types.Container{ + CreateMockContainer( + "test-container-01", + "test-container-01", + "fake-image:latest", + time.Now()), + }, + }, + false, + false, + ) + _, err := actions.Update(client, types.UpdateParams{Cleanup: true, MonitorOnly: true, LabelPrecedence: true}) + Expect(err).NotTo(HaveOccurred()) + Expect(client.TestData.TriedToRemoveImageCount).To(Equal(0)) + }) + }) }) })