knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/observability/runtime/config_test.go (about) 1 /* 2 Copyright 2025 The Knative Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package runtime 18 19 import ( 20 "testing" 21 22 "github.com/google/go-cmp/cmp" 23 ) 24 25 func TestNewFromMap(t *testing.T) { 26 got, err := NewFromMap(nil) 27 want := DefaultConfig() 28 29 if err != nil { 30 t.Error("unexpected error:", err) 31 } 32 33 if diff := cmp.Diff(want, got); diff != "" { 34 t.Error("unexpected diff (-want +got): ", diff) 35 } 36 } 37 38 func TestProfilingEnabled(t *testing.T) { 39 c := Config{Profiling: ProfilingEnabled} 40 if !c.ProfilingEnabled() { 41 t.Error("profiling should be enabled") 42 } 43 } 44 45 func TestNewFromMapBadInput(t *testing.T) { 46 cases := []struct { 47 name string 48 m map[string]string 49 }{{ 50 name: "unsupported profiling setting", 51 m: map[string]string{"runtime-profiling": "bad-setting"}, 52 }, { 53 name: "bad export interval - negative number", 54 m: map[string]string{"runtime-export-interval": "-1s"}, 55 }, { 56 name: "bad export interval - not an integer", 57 m: map[string]string{"runtime-export-interval": "bad-interval"}, 58 }} 59 60 for _, tc := range cases { 61 t.Run(tc.name, func(t *testing.T) { 62 if _, err := NewFromMap(tc.m); err == nil { 63 t.Error("expected an error") 64 } 65 }) 66 } 67 }