tanmayrauth commented on code in PR #1430:
URL: https://github.com/apache/iceberg-go/pull/1430#discussion_r3560663298


##########
metrics/registry_test.go:
##########
@@ -0,0 +1,79 @@
+// 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.
+
+package metrics
+
+import (
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+func TestFromProperties(t *testing.T) {
+       t.Run("absent name yields NopReporter", func(t *testing.T) {
+               r, err := FromProperties(nil)
+               require.NoError(t, err)
+               assert.IsType(t, NopReporter{}, r)
+       })
+
+       t.Run("empty name yields NopReporter", func(t *testing.T) {
+               r, err := FromProperties(map[string]string{ReporterImplKey: ""})
+               require.NoError(t, err)
+               assert.IsType(t, NopReporter{}, r)
+       })
+
+       t.Run("nop name yields NopReporter", func(t *testing.T) {
+               r, err := FromProperties(map[string]string{ReporterImplKey: 
"nop"})
+               require.NoError(t, err)
+               assert.IsType(t, NopReporter{}, r)
+       })
+
+       t.Run("logging name yields LoggingReporter", func(t *testing.T) {
+               r, err := FromProperties(map[string]string{ReporterImplKey: 
"logging"})
+               require.NoError(t, err)
+               assert.IsType(t, &LoggingReporter{}, r)
+       })
+
+       t.Run("unknown name is an error", func(t *testing.T) {
+               _, err := FromProperties(map[string]string{ReporterImplKey: 
"does-not-exist"})
+               assert.Error(t, err)
+       })
+}
+
+func TestRegister(t *testing.T) {
+       t.Run("factory is selectable via FromProperties", func(t *testing.T) {
+               Register("test-custom", func(props map[string]string) 
(Reporter, error) {

Review Comment:
   Added a Deregister(name) and TestRegister now does t.Cleanup(func(){ 
Deregister("test-custom") }). Confirmed go test -count=2 ./metrics/ passes now. 
Kept the global registry for this PR rather than reshaping into a  
struct-with-methods.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to