Browse Source

Added test loggers.

Christopher Manzi 1 month ago
parent
commit
a931e604e0

+ 2
- 2
pkg/cluster/kubernetes/kubernetes_test.go View File

@@ -6,7 +6,7 @@ import (
6 6
 	"sort"
7 7
 	"testing"
8 8
 
9
-	"github.com/go-kit/kit/log"
9
+	"go.uber.org/zap"
10 10
 	apiv1 "k8s.io/api/core/v1"
11 11
 	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12 12
 	fakekubernetes "k8s.io/client-go/kubernetes/fake"
@@ -32,7 +32,7 @@ func testGetAllowedNamespaces(t *testing.T, namespace []string, expected []strin
32 32
 	for _, n := range namespace {
33 33
 		allowedNamespaces[n] = struct{}{}
34 34
 	}
35
-	c := NewCluster(client, nil, nil, log.NewNopLogger(), allowedNamespaces, []string{}, []string{})
35
+	c := NewCluster(client, nil, nil, zap.NewNop().Sugar(), allowedNamespaces, []string{}, []string{})
36 36
 
37 37
 	namespaces, err := c.getAllowedAndExistingNamespaces(context.Background())
38 38
 	if err != nil {

+ 20
- 4
pkg/cluster/kubernetes/manifests_test.go View File

@@ -3,23 +3,31 @@ package kubernetes
3 3
 import (
4 4
 	"bytes"
5 5
 	"io/ioutil"
6
-	"os"
7 6
 	"path/filepath"
8 7
 	"testing"
9 8
 
10
-	"github.com/go-kit/kit/log"
11 9
 	"github.com/stretchr/testify/assert"
10
+	"go.uber.org/zap"
11
+	"go.uber.org/zap/zapcore"
12 12
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13 13
 
14 14
 	"github.com/fluxcd/flux/pkg/cluster/kubernetes/testfiles"
15 15
 )
16 16
 
17 17
 func TestLocalCRDScope(t *testing.T) {
18
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
19
+		enc := zapLogfmt.NewEncoder(config)
20
+		return enc, nil
21
+	})
22
+	logCfg := zap.NewDevelopmentConfig()
23
+	logCfg.Encoding = "logfmt"
24
+	logger, _ := logCfg.Build()
25
+	sugaredLogger := logger.Sugar()
18 26
 	coreClient := makeFakeClient()
19 27
 
20 28
 	nser, err := NewNamespacer(coreClient.Discovery(), "")
21 29
 	assert.NoError(t, err)
22
-	manifests := NewManifests(nser, log.NewLogfmtLogger(os.Stdout))
30
+	manifests := NewManifests(nser, sugaredLogger)
23 31
 
24 32
 	dir, cleanup := testfiles.TempDir(t)
25 33
 	defer cleanup()
@@ -62,12 +70,20 @@ metadata:
62 70
 }
63 71
 
64 72
 func TestUnKnownCRDScope(t *testing.T) {
73
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
74
+		enc := zapLogfmt.NewEncoder(config)
75
+		return enc, nil
76
+	})
77
+	logCfg := zap.NewDevelopmentConfig()
78
+	logCfg.Encoding = "logfmt"
79
+	logger, _ := logCfg.Build()
80
+	sugaredLogger := logger.Sugar()
65 81
 	coreClient := makeFakeClient()
66 82
 
67 83
 	nser, err := NewNamespacer(coreClient.Discovery(), "")
68 84
 	assert.NoError(t, err)
69 85
 	logBuffer := bytes.NewBuffer(nil)
70
-	manifests := NewManifests(nser, log.NewLogfmtLogger(logBuffer))
86
+	manifests := NewManifests(nser, sugaredLogger)
71 87
 
72 88
 	dir, cleanup := testfiles.TempDir(t)
73 89
 	defer cleanup()

+ 11
- 3
pkg/cluster/kubernetes/policies_test.go View File

@@ -2,18 +2,26 @@ package kubernetes
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"os"
6 5
 	"testing"
7 6
 	"text/template"
8 7
 
9
-	"github.com/go-kit/kit/log"
10 8
 	"github.com/stretchr/testify/assert"
9
+	"go.uber.org/zap"
10
+	"go.uber.org/zap/zapcore"
11 11
 
12 12
 	"github.com/fluxcd/flux/pkg/policy"
13 13
 	"github.com/fluxcd/flux/pkg/resource"
14 14
 )
15 15
 
16 16
 func TestUpdatePolicies(t *testing.T) {
17
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
18
+		enc := zapLogfmt.NewEncoder(config)
19
+		return enc, nil
20
+	})
21
+	logCfg := zap.NewDevelopmentConfig()
22
+	logCfg.Encoding = "logfmt"
23
+	logger, _ := logCfg.Build()
24
+	sugaredLogger := logger.Sugar()
17 25
 	for _, c := range []struct {
18 26
 		name    string
19 27
 		in, out []string
@@ -191,7 +199,7 @@ func TestUpdatePolicies(t *testing.T) {
191 199
 			caseIn := templToString(t, annotationsTemplate, cLocal.in)
192 200
 			caseOut := templToString(t, annotationsTemplate, cLocal.out)
193 201
 			resourceID := resource.MustParseID("default:deployment/nginx")
194
-			manifests := NewManifests(ConstNamespacer("default"), log.NewLogfmtLogger(os.Stdout))
202
+			manifests := NewManifests(ConstNamespacer("default"), sugaredLogger)
195 203
 			out, err := manifests.UpdateWorkloadPolicies([]byte(caseIn), resourceID, cLocal.update)
196 204
 			assert.Equal(t, cLocal.wantErr, err != nil, "unexpected error value: %s", err)
197 205
 			if !cLocal.wantErr {

+ 20
- 3
pkg/cluster/kubernetes/sync_test.go View File

@@ -2,7 +2,6 @@ package kubernetes
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"os"
6 5
 	"sort"
7 6
 	"strings"
8 7
 	"testing"
@@ -10,6 +9,8 @@ import (
10 9
 	"github.com/ghodss/yaml"
11 10
 	"github.com/go-kit/kit/log"
12 11
 	"github.com/stretchr/testify/assert"
12
+	"go.uber.org/zap"
13
+	"go.uber.org/zap/zapcore"
13 14
 	corev1 "k8s.io/api/core/v1"
14 15
 	crdfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
15 16
 	"k8s.io/apimachinery/pkg/api/errors"
@@ -238,12 +239,20 @@ func findAPIResource(gvr schema.GroupVersionResource, disco discovery.DiscoveryI
238 239
 // ---
239 240
 
240 241
 func setup(t *testing.T) (*Cluster, *fakeApplier, func()) {
242
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
243
+		enc := zapLogfmt.NewEncoder(config)
244
+		return enc, nil
245
+	})
246
+	logCfg := zap.NewDevelopmentConfig()
247
+	logCfg.Encoding = "logfmt"
248
+	logger, _ := logCfg.Build()
249
+	sugaredLogger := logger.Sugar()
241 250
 	clients, cancel := fakeClients()
242 251
 	applier := &fakeApplier{dynamicClient: clients.dynamicClient, coreClient: clients.coreClient, defaultNS: defaultTestNamespace}
243 252
 	kube := &Cluster{
244 253
 		applier:             applier,
245 254
 		client:              clients,
246
-		logger:              log.NewLogfmtLogger(os.Stdout),
255
+		logger:              sugaredLogger,
247 256
 		resourceExcludeList: []string{"*metrics.k8s.io/*", "webhook.certmanager.k8s.io/v1beta1/*"},
248 257
 	}
249 258
 	return kube, applier, cancel
@@ -316,6 +325,14 @@ func TestSyncTolerateMetricsErrors(t *testing.T) {
316 325
 }
317 326
 
318 327
 func TestSync(t *testing.T) {
328
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
329
+		enc := zapLogfmt.NewEncoder(config)
330
+		return enc, nil
331
+	})
332
+	logCfg := zap.NewDevelopmentConfig()
333
+	logCfg.Encoding = "logfmt"
334
+	logger, _ := logCfg.Build()
335
+	sugaredLogger := logger.Sugar()
319 336
 	const ns1 = `---
320 337
 apiVersion: v1
321 338
 kind: Namespace
@@ -376,7 +393,7 @@ metadata:
376 393
 		if err != nil {
377 394
 			t.Fatal(err)
378 395
 		}
379
-		manifests := NewManifests(namespacer, log.NewLogfmtLogger(os.Stdout))
396
+		manifests := NewManifests(namespacer, sugaredLogger)
380 397
 
381 398
 		resources0, err := kresource.ParseMultidoc([]byte(defs), "before")
382 399
 		if err != nil {

+ 1
- 3
pkg/daemon/daemon_test.go View File

@@ -11,14 +11,12 @@ import (
11 11
 	"testing"
12 12
 	"time"
13 13
 
14
-	"github.com/go-kit/kit/log"
15 14
 	"go.uber.org/zap"
16 15
 
17 16
 	"github.com/stretchr/testify/assert"
18 17
 
19 18
 	"github.com/fluxcd/flux/pkg/api/v10"
20 19
 	v10 "github.com/fluxcd/flux/pkg/api/v10"
21
-	"github.com/fluxcd/flux/pkg/api/v11"
22 20
 	v11 "github.com/fluxcd/flux/pkg/api/v11"
23 21
 	v6 "github.com/fluxcd/flux/pkg/api/v6"
24 22
 	v9 "github.com/fluxcd/flux/pkg/api/v9"
@@ -728,7 +726,7 @@ func mockDaemon(t *testing.T) (*Daemon, func(), func(), *mock.Mock, *mockEventWr
728 726
 	// Jobs queue (starts itself)
729 727
 	jobs := job.NewQueue(jshutdown, jwg)
730 728
 
731
-	manifests := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), log.NewLogfmtLogger(os.Stdout))
729
+	manifests := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), logger)
732 730
 
733 731
 	gitSync, _ := fluxsync.NewGitTagSyncProvider(repo, syncTag, "", false, params)
734 732
 

+ 4
- 4
pkg/daemon/images_test.go View File

@@ -4,7 +4,7 @@ import (
4 4
 	"testing"
5 5
 	"time"
6 6
 
7
-	"github.com/go-kit/kit/log"
7
+	"go.uber.org/zap"
8 8
 
9 9
 	"github.com/fluxcd/flux/pkg/cluster"
10 10
 	"github.com/fluxcd/flux/pkg/image"
@@ -53,7 +53,7 @@ func (candidate) Bytes() []byte {
53 53
 }
54 54
 
55 55
 func TestCalculateChanges_Automated(t *testing.T) {
56
-	logger := log.NewNopLogger()
56
+	logger := zap.NewNop().Sugar()
57 57
 	resourceID := resource.MakeID(ns, "deployment", "application")
58 58
 	candidateWorkloads := resources{
59 59
 		resourceID: candidate{
@@ -101,7 +101,7 @@ func TestCalculateChanges_Automated(t *testing.T) {
101 101
 	}
102 102
 }
103 103
 func TestCalculateChanges_UntaggedImage(t *testing.T) {
104
-	logger := log.NewNopLogger()
104
+	logger := zap.NewNop().Sugar()
105 105
 	resourceID := resource.MakeID(ns, "deployment", "application")
106 106
 	candidateWorkloads := resources{
107 107
 		resourceID: candidate{
@@ -158,7 +158,7 @@ func TestCalculateChanges_UntaggedImage(t *testing.T) {
158 158
 }
159 159
 
160 160
 func TestCalculateChanges_ZeroTimestamp(t *testing.T) {
161
-	logger := log.NewNopLogger()
161
+	logger := zap.NewNop().Sugar()
162 162
 	resourceID := resource.MakeID(ns, "deployment", "application")
163 163
 	candidateWorkloads := resources{
164 164
 		resourceID: candidate{

+ 12
- 4
pkg/daemon/sync_test.go View File

@@ -5,7 +5,6 @@ import (
5 5
 	"context"
6 6
 	"fmt"
7 7
 	"io/ioutil"
8
-	"os"
9 8
 	"path"
10 9
 	"reflect"
11 10
 	"sync"
@@ -24,9 +23,10 @@ import (
24 23
 	registryMock "github.com/fluxcd/flux/pkg/registry/mock"
25 24
 	"github.com/fluxcd/flux/pkg/resource"
26 25
 	fluxsync "github.com/fluxcd/flux/pkg/sync"
27
-	"github.com/go-kit/kit/log"
28 26
 	"github.com/prometheus/client_golang/prometheus"
29 27
 	promdto "github.com/prometheus/client_model/go"
28
+	"go.uber.org/zap"
29
+	"go.uber.org/zap/zapcore"
30 30
 )
31 31
 
32 32
 const (
@@ -42,6 +42,14 @@ var (
42 42
 )
43 43
 
44 44
 func daemon(t *testing.T) (*Daemon, func()) {
45
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
46
+		enc := zapLogfmt.NewEncoder(config)
47
+		return enc, nil
48
+	})
49
+	logCfg := zap.NewDevelopmentConfig()
50
+	logCfg.Encoding = "logfmt"
51
+	logger, _ := logCfg.Build()
52
+	sugaredLogger := logger.Sugar()
45 53
 	repo, repoCleanup := gittest.Repo(t)
46 54
 
47 55
 	k8s = &mock.Mock{}
@@ -63,7 +71,7 @@ func daemon(t *testing.T) (*Daemon, func()) {
63 71
 		UserEmail: gitEmail,
64 72
 	}
65 73
 
66
-	manifests := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), log.NewLogfmtLogger(os.Stdout))
74
+	manifests := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), sugaredLogger)
67 75
 
68 76
 	jobs := job.NewQueue(shutdown, wg)
69 77
 	d := &Daemon{
@@ -75,7 +83,7 @@ func daemon(t *testing.T) (*Daemon, func()) {
75 83
 		Jobs:           jobs,
76 84
 		JobStatusCache: &job.StatusCache{Size: 100},
77 85
 		EventWriter:    events,
78
-		Logger:         log.NewLogfmtLogger(os.Stdout),
86
+		Logger:         sugaredLogger,
79 87
 		LoopVars:       &LoopVars{SyncTimeout: timeout, GitTimeout: timeout},
80 88
 	}
81 89
 	return d, func() {

+ 11
- 2
pkg/manifests/configaware_test.go View File

@@ -7,8 +7,9 @@ import (
7 7
 	"path/filepath"
8 8
 	"testing"
9 9
 
10
-	"github.com/go-kit/kit/log"
11 10
 	"github.com/stretchr/testify/assert"
11
+	"go.uber.org/zap"
12
+	"go.uber.org/zap/zapcore"
12 13
 
13 14
 	"github.com/fluxcd/flux/pkg/cluster/kubernetes"
14 15
 	"github.com/fluxcd/flux/pkg/cluster/kubernetes/testfiles"
@@ -30,7 +31,15 @@ type config struct {
30 31
 // and the config locations don't necessarily have to line up. You can
31 32
 // pass `nil` for the paths, to indicate "just use the base path".
32 33
 func setup(t *testing.T, paths []string, configs ...config) (*configAware, string, func()) {
33
-	manifests := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), log.NewLogfmtLogger(os.Stdout))
34
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
35
+		enc := zapLogfmt.NewEncoder(config)
36
+		return enc, nil
37
+	})
38
+	logCfg := zap.NewDevelopmentConfig()
39
+	logCfg.Encoding = "logfmt"
40
+	logger, _ := logCfg.Build()
41
+	sugaredLogger := logger.Sugar()
42
+	manifests := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), sugaredLogger)
34 43
 	baseDir, cleanup := testfiles.TempDir(t)
35 44
 
36 45
 	// te constructor NewConfigAware expects at least one absolute path.

+ 12
- 5
pkg/registry/cache/repocachemanager_test.go View File

@@ -5,12 +5,12 @@ import (
5 5
 	"net/http"
6 6
 	"net/http/httptest"
7 7
 	"net/url"
8
-	"os"
9 8
 	"testing"
10 9
 	"time"
11 10
 
12
-	"github.com/go-kit/kit/log"
13 11
 	"github.com/stretchr/testify/assert"
12
+	"go.uber.org/zap"
13
+	"go.uber.org/zap/zapcore"
14 14
 
15 15
 	"github.com/fluxcd/flux/pkg/image"
16 16
 	"github.com/fluxcd/flux/pkg/registry"
@@ -25,9 +25,16 @@ func Test_ClientTimeouts(t *testing.T) {
25 25
 	defer server.Close()
26 26
 	url, err := url.Parse(server.URL)
27 27
 	assert.NoError(t, err)
28
-	logger := log.NewLogfmtLogger(os.Stdout)
28
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
29
+		enc := zapLogfmt.NewEncoder(config)
30
+		return enc, nil
31
+	})
32
+	logCfg := zap.NewDevelopmentConfig()
33
+	logCfg.Encoding = "logfmt"
34
+	logger, _ := logCfg.Build()
35
+	sugaredLogger := logger.Sugar()
29 36
 	cf := &registry.RemoteClientFactory{
30
-		Logger:        log.NewLogfmtLogger(os.Stdout),
37
+		Logger:        sugaredLogger,
31 38
 		Limiters:      nil,
32 39
 		Trace:         false,
33 40
 		InsecureHosts: []string{url.Host},
@@ -44,7 +51,7 @@ func Test_ClientTimeouts(t *testing.T) {
44 51
 		timeout,
45 52
 		1,
46 53
 		false,
47
-		logger,
54
+		sugaredLogger,
48 55
 		nil,
49 56
 	)
50 57
 	assert.NoError(t, err)

+ 14
- 5
pkg/registry/cache/warming_test.go View File

@@ -7,8 +7,9 @@ import (
7 7
 	"time"
8 8
 
9 9
 	"github.com/docker/distribution/registry/api/errcode"
10
-	"github.com/go-kit/kit/log"
11 10
 	"github.com/stretchr/testify/assert"
11
+	"go.uber.org/zap"
12
+	"go.uber.org/zap/zapcore"
12 13
 
13 14
 	"github.com/fluxcd/flux/pkg/image"
14 15
 	"github.com/fluxcd/flux/pkg/registry"
@@ -66,12 +67,20 @@ func (c *mem) GetKey(k Keyer) ([]byte, time.Time, error) {
66 67
 // warmer to fetch information, the cached gets populated, and the
67 68
 // Registry implementation will see it.
68 69
 func TestWarmThenQuery(t *testing.T) {
70
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
71
+		enc := zapLogfmt.NewEncoder(config)
72
+		return enc, nil
73
+	})
74
+	logCfg := zap.NewDevelopmentConfig()
75
+	logCfg.Encoding = "logfmt"
76
+	logger, _ := logCfg.Build()
77
+	sugaredLogger := logger.Sugar()
69 78
 	digest := "abc"
70 79
 	warmer, cache := setup(t, &digest)
71
-	logger := log.NewNopLogger()
80
+	logger := zap.NewNop().Sugar()
72 81
 
73 82
 	now := time.Now()
74
-	warmer.warm(context.TODO(), now, logger, repo, registry.NoCredentials())
83
+	warmer.warm(context.TODO(), now, sugaredLogger, repo, registry.NoCredentials())
75 84
 
76 85
 	registry := &Cache{Reader: cache}
77 86
 	repoInfo, err := registry.GetImageRepositoryMetadata(ref.Name)
@@ -107,7 +116,7 @@ func TestWarmManifestUnknown(t *testing.T) {
107 116
 	cache := &mem{}
108 117
 	warmer := &Warmer{clientFactory: factory, cache: cache, burst: 10}
109 118
 
110
-	logger := log.NewNopLogger()
119
+	logger := zap.NewNop().Sugar()
111 120
 
112 121
 	now := time.Now()
113 122
 	redisRef, _ := image.ParseRef("bitnami/redis:5.0.2")
@@ -125,7 +134,7 @@ func TestWarmManifestUnknown(t *testing.T) {
125 134
 func TestRefreshDeadline(t *testing.T) {
126 135
 	digest := "abc"
127 136
 	warmer, cache := setup(t, &digest)
128
-	logger := log.NewNopLogger()
137
+	logger := zap.NewNop().Sugar()
129 138
 
130 139
 	now0 := time.Now()
131 140
 	warmer.warm(context.TODO(), now0, logger, repo, registry.NoCredentials())

+ 22
- 4
pkg/release/releaser_test.go View File

@@ -4,13 +4,12 @@ import (
4 4
 	"context"
5 5
 	"errors"
6 6
 	"fmt"
7
-	"os"
8 7
 	"reflect"
9 8
 	"testing"
10 9
 	"time"
11 10
 
12
-	"github.com/go-kit/kit/log"
13 11
 	"go.uber.org/zap"
12
+	"go.uber.org/zap/zapcore"
14 13
 
15 14
 	"github.com/stretchr/testify/assert"
16 15
 
@@ -140,7 +139,18 @@ var (
140 139
 			},
141 140
 		},
142 141
 	}
143
-	mockManifests = kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), log.NewLogfmtLogger(os.Stdout))
142
+	testLogger = func() *zap.SugaredLogger {
143
+		zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
144
+			enc := zapLogfmt.NewEncoder(config)
145
+			return enc, nil
146
+		})
147
+		logCfg := zap.NewDevelopmentConfig()
148
+		logCfg.Encoding = "logfmt"
149
+		logger, _ := logCfg.Build()
150
+		sugaredLogger := logger.Sugar()
151
+		return sugaredLogger
152
+	}()
153
+	mockManifests = kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), testLogger)
144 154
 )
145 155
 
146 156
 func mockCluster(running ...cluster.Workload) *mock.Mock {
@@ -1061,6 +1071,14 @@ func (m *badManifests) SetWorkloadContainerImage(def []byte, id resource.ID, con
1061 1071
 }
1062 1072
 
1063 1073
 func Test_BadRelease(t *testing.T) {
1074
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
1075
+		enc := zapLogfmt.NewEncoder(config)
1076
+		return enc, nil
1077
+	})
1078
+	logCfg := zap.NewDevelopmentConfig()
1079
+	logCfg.Encoding = "logfmt"
1080
+	logger, _ := logCfg.Build()
1081
+	sugaredLogger := logger.Sugar()
1064 1082
 	mCluster := mockCluster(hwSvc)
1065 1083
 	spec := update.ReleaseImageSpec{
1066 1084
 		ServiceSpecs: []update.ResourceSpec{update.ResourceSpecAll},
@@ -1071,7 +1089,7 @@ func Test_BadRelease(t *testing.T) {
1071 1089
 	checkout1, cleanup1 := setup(t)
1072 1090
 	defer cleanup1()
1073 1091
 
1074
-	manifests := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), log.NewLogfmtLogger(os.Stdout))
1092
+	manifests := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), sugaredLogger)
1075 1093
 	ctx := context.Background()
1076 1094
 	rc := &ReleaseContext{
1077 1095
 		cluster:       mCluster,

+ 11
- 3
pkg/sync/sync_test.go View File

@@ -2,11 +2,11 @@ package sync
2 2
 
3 3
 import (
4 4
 	"context"
5
-	"os"
6 5
 	"testing"
7 6
 
8
-	"github.com/go-kit/kit/log"
9 7
 	"github.com/stretchr/testify/assert"
8
+	"go.uber.org/zap"
9
+	"go.uber.org/zap/zapcore"
10 10
 
11 11
 	"github.com/fluxcd/flux/pkg/cluster"
12 12
 	"github.com/fluxcd/flux/pkg/cluster/kubernetes"
@@ -19,11 +19,19 @@ import (
19 19
 // Test that cluster.Sync gets called with the appropriate things when
20 20
 // run.
21 21
 func TestSync(t *testing.T) {
22
+	zap.RegisterEncoder("logfmt", func(config zapcore.EncoderConfig) (zapcore.Encoder, error) {
23
+		enc := zapLogfmt.NewEncoder(config)
24
+		return enc, nil
25
+	})
26
+	logCfg := zap.NewDevelopmentConfig()
27
+	logCfg.Encoding = "logfmt"
28
+	logger, _ := logCfg.Build()
29
+	sugaredLogger := logger.Sugar()
22 30
 	checkout, cleanup := setup(t)
23 31
 	defer cleanup()
24 32
 
25 33
 	// Start with nothing running. We should be told to apply all the things.
26
-	parser := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), log.NewLogfmtLogger(os.Stdout))
34
+	parser := kubernetes.NewManifests(kubernetes.ConstNamespacer("default"), sugaredLogger)
27 35
 	clus := &syncCluster{map[string]string{}}
28 36
 
29 37
 	dirs := checkout.AbsolutePaths()

Loading…
Cancel
Save