mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
fix: migrate from github.com/rs/zerolog to golang-native log/slog (#3405)
* fix: migrate from github.com/rs/zerolog to golang-native log/slog We have been using zerolog for a really long time. golang now has structured logging using slog. Best to move to this in interests of long-term support. This is a tech debt item. Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com> * fix: a few changes on top Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com> * fix: address comments Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com> --------- Signed-off-by: Ramkumar Chinchani <rchincha.dev@gmail.com>
This commit is contained in:
committed by
GitHub
parent
d5779cfec8
commit
b1842ab9e0
@@ -903,7 +903,7 @@ func TestAPIKeysOpenDBError(t *testing.T) {
|
||||
|
||||
func TestAPIKeysGeneratorErrors(t *testing.T) {
|
||||
Convey("Test API keys - unable to generate API keys and API Key IDs", t, func() {
|
||||
log := log.NewLogger("debug", "")
|
||||
log := log.NewTestLogger()
|
||||
|
||||
apiKey, apiKeyID, err := api.GenerateAPIKey(guuid.DefaultGenerator, log)
|
||||
So(err, ShouldBeNil)
|
||||
@@ -931,7 +931,7 @@ func TestAPIKeysGeneratorErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCookiestoreCleanup(t *testing.T) {
|
||||
log := log.Logger{}
|
||||
log := log.NewTestLogger()
|
||||
metrics := monitoring.NewMetricsServer(true, log)
|
||||
|
||||
Convey("Test cookiestore cleanup works", t, func() {
|
||||
|
||||
@@ -22,9 +22,8 @@ func TestRedisLogger(t *testing.T) {
|
||||
logFile, err := os.CreateTemp(t.TempDir(), "zot-log*.txt")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
logger := log.NewLogger("debug", logFile.Name())
|
||||
writers := io.MultiWriter(os.Stdout, logFile)
|
||||
logger.Logger = logger.Output(writers)
|
||||
logger := log.NewLoggerWithWriter("debug", writers)
|
||||
|
||||
rlog := rediscfg.RedisLogger{logger}
|
||||
rlog.Printf(context.Background(), "this is a rest string")
|
||||
@@ -38,7 +37,7 @@ func TestRedisLogger(t *testing.T) {
|
||||
|
||||
func TestRedisOptions(t *testing.T) {
|
||||
Convey("Test redis initialization", t, func() {
|
||||
log := log.NewLogger("debug", "")
|
||||
log := log.NewTestLogger()
|
||||
So(log, ShouldNotBeNil)
|
||||
|
||||
Convey("Test redis url parsing", func() {
|
||||
|
||||
@@ -98,7 +98,7 @@ func NewController(appConfig *config.Config) *Controller {
|
||||
}
|
||||
appConfig.Cluster.Proxy = internalProxyConfig
|
||||
|
||||
logger.Logger = logger.Logger.With().
|
||||
logger = logger.With().
|
||||
Str("clusterMember", memberSocket).
|
||||
Str("clusterMemberIndex", strconv.Itoa(memberSocketIdx)).Logger()
|
||||
}
|
||||
|
||||
+28
-21
@@ -139,7 +139,7 @@ func TestNew(t *testing.T) {
|
||||
|
||||
func TestCreateCacheDatabaseDriver(t *testing.T) {
|
||||
Convey("Test CreateCacheDatabaseDriver boltdb", t, func() {
|
||||
log := log.NewLogger("debug", "")
|
||||
log := log.NewTestLogger()
|
||||
|
||||
// fail create db, no perm
|
||||
dir := t.TempDir()
|
||||
@@ -167,7 +167,7 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
|
||||
Convey("Test CreateCacheDatabaseDriver redisdb", t, func() {
|
||||
miniRedis := miniredis.RunT(t)
|
||||
|
||||
log := log.NewLogger("debug", "")
|
||||
log := log.NewTestLogger()
|
||||
|
||||
dir := t.TempDir()
|
||||
conf := config.New()
|
||||
@@ -216,7 +216,7 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
|
||||
tskip.SkipDynamo(t)
|
||||
tskip.SkipS3(t)
|
||||
Convey("Test CreateCacheDatabaseDriver dynamodb", t, func() {
|
||||
log := log.NewLogger("debug", "")
|
||||
log := log.NewTestLogger()
|
||||
dir := t.TempDir()
|
||||
// good config
|
||||
conf := config.New()
|
||||
@@ -310,7 +310,7 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
|
||||
|
||||
func TestCreateMetaDBDriver(t *testing.T) {
|
||||
Convey("Test create MetaDB dynamo", t, func() {
|
||||
log := log.NewLogger("debug", "")
|
||||
log := log.NewTestLogger()
|
||||
dir := t.TempDir()
|
||||
conf := config.New()
|
||||
conf.Storage.RootDirectory = dir
|
||||
@@ -389,7 +389,7 @@ func TestCreateMetaDBDriver(t *testing.T) {
|
||||
Convey("Test create MetaDB redis", t, func() {
|
||||
miniRedis := miniredis.RunT(t)
|
||||
|
||||
log := log.NewLogger("debug", "")
|
||||
log := log.NewTestLogger()
|
||||
dir := t.TempDir()
|
||||
conf := config.New()
|
||||
conf.Storage.RootDirectory = dir
|
||||
@@ -440,7 +440,7 @@ func TestCreateMetaDBDriver(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Test create MetaDB bolt", t, func() {
|
||||
log := log.NewLogger("debug", "")
|
||||
log := log.NewTestLogger()
|
||||
dir := t.TempDir()
|
||||
conf := config.New()
|
||||
conf.Storage.RootDirectory = dir
|
||||
@@ -2490,7 +2490,7 @@ func TestAuthnErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
So(func() {
|
||||
api.NewRelyingPartyGithub(conf, "prov", nil, nil, log.NewLogger("debug", ""))
|
||||
api.NewRelyingPartyGithub(conf, "prov", nil, nil, log.NewTestLogger())
|
||||
}, ShouldPanic)
|
||||
})
|
||||
}
|
||||
@@ -3810,27 +3810,29 @@ func TestLDAPFailures(t *testing.T) {
|
||||
defer ldapServer.Stop()
|
||||
|
||||
Convey("Empty config", func() {
|
||||
lc := &api.LDAPClient{}
|
||||
err := lc.Connect()
|
||||
lclient := &api.LDAPClient{Log: log.NewTestLogger()}
|
||||
err := lclient.Connect()
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("Basic connectivity config", func() {
|
||||
lc := &api.LDAPClient{
|
||||
lclient := &api.LDAPClient{
|
||||
Host: LDAPAddress,
|
||||
Port: ldapPort,
|
||||
Log: log.NewTestLogger(),
|
||||
}
|
||||
err := lc.Connect()
|
||||
err := lclient.Connect()
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("Basic TLS connectivity config", func() {
|
||||
lc := &api.LDAPClient{
|
||||
lclient := &api.LDAPClient{
|
||||
Host: LDAPAddress,
|
||||
Port: ldapPort,
|
||||
UseSSL: true,
|
||||
Log: log.NewTestLogger(),
|
||||
}
|
||||
err := lc.Connect()
|
||||
err := lclient.Connect()
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
@@ -3853,6 +3855,7 @@ func TestLDAPClient(t *testing.T) {
|
||||
BindDN: "bad-user",
|
||||
BindPassword: "bad-pass",
|
||||
SkipTLS: true,
|
||||
Log: log.NewTestLogger(),
|
||||
}
|
||||
|
||||
_, _, _, err = lClient.Authenticate("bad-user", "bad-pass")
|
||||
@@ -3865,6 +3868,7 @@ func TestLDAPClient(t *testing.T) {
|
||||
BindDN: "bad-user",
|
||||
BindPassword: "",
|
||||
SkipTLS: true,
|
||||
Log: log.NewTestLogger(),
|
||||
}
|
||||
|
||||
_, _, _, err = lClient.Authenticate("user", "")
|
||||
@@ -3880,6 +3884,7 @@ func TestLDAPClient(t *testing.T) {
|
||||
UserAttribute: LDAPUserAttr,
|
||||
UserFilter: "",
|
||||
SkipTLS: true,
|
||||
Log: log.NewTestLogger(),
|
||||
}
|
||||
|
||||
_, _, _, err = lClient.Authenticate("fail-user-bind", "")
|
||||
@@ -3895,6 +3900,7 @@ func TestLDAPClient(t *testing.T) {
|
||||
UserAttribute: LDAPUserAttr,
|
||||
UserFilter: "",
|
||||
SkipTLS: true,
|
||||
Log: log.NewTestLogger(),
|
||||
}
|
||||
|
||||
_, _, _, err = lClient.Authenticate("fail-user-bind", "pass")
|
||||
@@ -3910,6 +3916,7 @@ func TestLDAPClient(t *testing.T) {
|
||||
UserAttribute: LDAPUserAttr,
|
||||
UserFilter: "(!(nsaccountlock=TRUE))",
|
||||
SkipTLS: true,
|
||||
Log: log.NewTestLogger(),
|
||||
}
|
||||
|
||||
_, _, _, err = lClient.Authenticate("locked-user", "pass")
|
||||
@@ -4487,7 +4494,7 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
|
||||
}
|
||||
|
||||
Convey("provider not found in config", func() {
|
||||
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "notDex", nil, nil, log.NewLogger("debug", "")) }, ShouldPanic)
|
||||
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "notDex", nil, nil, log.NewTestLogger()) }, ShouldPanic)
|
||||
})
|
||||
|
||||
Convey("key path not found on disk", func() {
|
||||
@@ -4495,7 +4502,7 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
|
||||
oidcProviderCfg.KeyPath = "path/to/file"
|
||||
conf.HTTP.Auth.OpenID.Providers["oidc"] = oidcProviderCfg
|
||||
|
||||
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "oidc", nil, nil, log.NewLogger("debug", "")) }, ShouldPanic)
|
||||
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "oidc", nil, nil, log.NewTestLogger()) }, ShouldPanic)
|
||||
})
|
||||
|
||||
Convey("https callback", func() {
|
||||
@@ -4504,7 +4511,7 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
|
||||
Key: ServerKey,
|
||||
}
|
||||
|
||||
rp := api.NewRelyingPartyOIDC(ctx, conf, "oidc", nil, nil, log.NewLogger("debug", ""))
|
||||
rp := api.NewRelyingPartyOIDC(ctx, conf, "oidc", nil, nil, log.NewTestLogger())
|
||||
So(rp, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
@@ -4513,7 +4520,7 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
|
||||
oidcProvider.ClientSecret = ""
|
||||
conf.HTTP.Auth.OpenID.Providers["oidc"] = oidcProvider
|
||||
|
||||
rp := api.NewRelyingPartyOIDC(ctx, conf, "oidc", nil, nil, log.NewLogger("debug", ""))
|
||||
rp := api.NewRelyingPartyOIDC(ctx, conf, "oidc", nil, nil, log.NewTestLogger())
|
||||
So(rp, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
@@ -4522,7 +4529,7 @@ func TestNewRelyingPartyOIDC(t *testing.T) {
|
||||
oidcProvider.Issuer = ""
|
||||
conf.HTTP.Auth.OpenID.Providers["oidc"] = oidcProvider
|
||||
|
||||
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "oidc", nil, nil, log.NewLogger("debug", "")) }, ShouldPanic)
|
||||
So(func() { _ = api.NewRelyingPartyOIDC(ctx, conf, "oidc", nil, nil, log.NewTestLogger()) }, ShouldPanic)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -12747,7 +12754,7 @@ func TestGetGithubUserInfo(t *testing.T) {
|
||||
|
||||
client := github.NewClient(mockedHTTPClient)
|
||||
|
||||
_, _, err := api.GetGithubUserInfo(context.Background(), client, log.Logger{})
|
||||
_, _, err := api.GetGithubUserInfo(context.Background(), client, log.NewTestLogger())
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
|
||||
@@ -12767,7 +12774,7 @@ func TestGetGithubUserInfo(t *testing.T) {
|
||||
|
||||
client := github.NewClient(mockedHTTPClient)
|
||||
|
||||
_, _, err := api.GetGithubUserInfo(context.Background(), client, log.Logger{})
|
||||
_, _, err := api.GetGithubUserInfo(context.Background(), client, log.NewTestLogger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
@@ -12796,7 +12803,7 @@ func TestGetGithubUserInfo(t *testing.T) {
|
||||
|
||||
client := github.NewClient(mockedHTTPClient)
|
||||
|
||||
_, _, err := api.GetGithubUserInfo(context.Background(), client, log.Logger{})
|
||||
_, _, err := api.GetGithubUserInfo(context.Background(), client, log.NewTestLogger())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1665,7 +1665,7 @@ func TestWriteDataFromReader(t *testing.T) {
|
||||
Convey("", t, func() {
|
||||
response := httptest.NewRecorder()
|
||||
api.WriteDataFromReader(response, 200, 100, ispec.MediaTypeImageManifest, readerThatFails{},
|
||||
log.NewLogger("debug", ""))
|
||||
log.NewTestLogger())
|
||||
|
||||
So(response.Code, ShouldEqual, 200)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user