nodece commented on PR #1234: URL: https://github.com/apache/pulsar-client-go/pull/1234#issuecomment-2209260330
> 1. Where should I place the test? You can write a test in the `pulsar/client_impl_with_slog_test.go`. > 2. What should I be testing? (that producer and consumer do not throw error when using Slog?) All right. > 3. How do I ensure my test is run only when we build for with go 1.21 ```go /// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. //go:build go1.21 package pulsar import "testing" func TestClientWithSlog(t *testing.T) { } ``` > For 2 you could see - in my PR description, I did an integration test where I started a producer with logrus, and producer with slog - and then I compared the output of both loggers, in terms of length and keys (since I was doing json). But this seems too complicated and not needed for what I was trying to test. > > So I would be provocative and ask, do we even need a test? You only need to verify the client with slog works fine. You can also verify the log output: ```go // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. //go:build go1.21 package log import ( "context" "log/slog" "testing" "github.com/stretchr/testify/assert" ) type defaultHandle struct { records []slog.Record } func (d *defaultHandle) Enabled(ctx context.Context, level slog.Level) bool { return true } func (d *defaultHandle) Handle(ctx context.Context, record slog.Record) error { d.records = append(d.records, record) return nil } func (d *defaultHandle) WithAttrs(attrs []slog.Attr) slog.Handler { panic("implement me") } func (d *defaultHandle) WithGroup(name string) slog.Handler { panic("implement me") } var _ slog.Handler = &defaultHandle{} func TestSlog(t *testing.T) { handler := &defaultHandle{} logger := slog.New(handler) logger.Info("1") assert.Equal(t, handler.records[0].Level, slog.LevelInfo) assert.Equal(t, handler.records[0].Message, "1") } ``` Thanks for your time! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org