Browse code

daemon: suppress logs in unit tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/10/17 09:47:37
Showing 4 changed files
... ...
@@ -24,6 +24,7 @@ func TestContainerWarningHostAndPublishPorts(t *testing.T) {
24 24
 			"8080": []nat.PortBinding{{HostPort: "8989"}},
25 25
 		}, warnings: []string{"Published ports are discarded when using host network mode"}},
26 26
 	}
27
+	muteLogs()
27 28
 
28 29
 	for _, tc := range testCases {
29 30
 		hostConfig := &containertypes.HostConfig{
... ...
@@ -68,6 +68,7 @@ func TestAdjustCPUShares(t *testing.T) {
68 68
 		repository: tmp,
69 69
 		root:       tmp,
70 70
 	}
71
+	muteLogs()
71 72
 
72 73
 	hostConfig := &containertypes.HostConfig{
73 74
 		Resources: containertypes.Resources{CPUShares: linuxMinCPUShares - 1},
... ...
@@ -78,6 +78,7 @@ func TestHealthStates(t *testing.T) {
78 78
 		EventsService:     e,
79 79
 		containersReplica: store,
80 80
 	}
81
+	muteLogs()
81 82
 
82 83
 	c.Config.Healthcheck = &containertypes.HealthConfig{
83 84
 		Retries: 1,
... ...
@@ -13,10 +13,16 @@ import (
13 13
 	_ "github.com/docker/docker/pkg/discovery/memory"
14 14
 	"github.com/docker/docker/registry"
15 15
 	"github.com/docker/libnetwork"
16
+	"github.com/sirupsen/logrus"
16 17
 	"gotest.tools/assert"
17 18
 	is "gotest.tools/assert/cmp"
18 19
 )
19 20
 
21
+// muteLogs suppresses logs that are generated during the test
22
+func muteLogs() {
23
+	logrus.SetLevel(logrus.ErrorLevel)
24
+}
25
+
20 26
 func TestDaemonReloadLabels(t *testing.T) {
21 27
 	daemon := &Daemon{
22 28
 		configStore: &config.Config{
... ...
@@ -26,6 +32,7 @@ func TestDaemonReloadLabels(t *testing.T) {
26 26
 		},
27 27
 		imageService: images.NewImageService(images.ImageServiceConfig{}),
28 28
 	}
29
+	muteLogs()
29 30
 
30 31
 	valuesSets := make(map[string]interface{})
31 32
 	valuesSets["labels"] = "foo:baz"
... ...
@@ -51,6 +58,7 @@ func TestDaemonReloadAllowNondistributableArtifacts(t *testing.T) {
51 51
 		configStore:  &config.Config{},
52 52
 		imageService: images.NewImageService(images.ImageServiceConfig{}),
53 53
 	}
54
+	muteLogs()
54 55
 
55 56
 	var err error
56 57
 	// Initialize daemon with some registries.
... ...
@@ -106,6 +114,8 @@ func TestDaemonReloadMirrors(t *testing.T) {
106 106
 	daemon := &Daemon{
107 107
 		imageService: images.NewImageService(images.ImageServiceConfig{}),
108 108
 	}
109
+	muteLogs()
110
+
109 111
 	var err error
110 112
 	daemon.RegistryService, err = registry.NewService(registry.ServiceOptions{
111 113
 		InsecureRegistries: []string{},
... ...
@@ -205,6 +215,8 @@ func TestDaemonReloadInsecureRegistries(t *testing.T) {
205 205
 	daemon := &Daemon{
206 206
 		imageService: images.NewImageService(images.ImageServiceConfig{}),
207 207
 	}
208
+	muteLogs()
209
+
208 210
 	var err error
209 211
 	// initialize daemon with existing insecure registries: "127.0.0.0/8", "10.10.1.11:5000", "10.10.1.22:5000"
210 212
 	daemon.RegistryService, err = registry.NewService(registry.ServiceOptions{
... ...
@@ -297,6 +309,8 @@ func TestDaemonReloadNotAffectOthers(t *testing.T) {
297 297
 	daemon := &Daemon{
298 298
 		imageService: images.NewImageService(images.ImageServiceConfig{}),
299 299
 	}
300
+	muteLogs()
301
+
300 302
 	daemon.configStore = &config.Config{
301 303
 		CommonConfig: config.CommonConfig{
302 304
 			Labels: []string{"foo:bar"},
... ...
@@ -331,6 +345,7 @@ func TestDaemonDiscoveryReload(t *testing.T) {
331 331
 	daemon := &Daemon{
332 332
 		imageService: images.NewImageService(images.ImageServiceConfig{}),
333 333
 	}
334
+	muteLogs()
334 335
 	daemon.configStore = &config.Config{
335 336
 		CommonConfig: config.CommonConfig{
336 337
 			ClusterStore:     "memory://127.0.0.1",
... ...
@@ -411,6 +426,7 @@ func TestDaemonDiscoveryReloadFromEmptyDiscovery(t *testing.T) {
411 411
 		imageService: images.NewImageService(images.ImageServiceConfig{}),
412 412
 	}
413 413
 	daemon.configStore = &config.Config{}
414
+	muteLogs()
414 415
 
415 416
 	valuesSet := make(map[string]interface{})
416 417
 	valuesSet["cluster-store"] = "memory://127.0.0.1:2222"