github.com/OpsMx/go-app-base@v0.0.24/birger/config_test.go (about) 1 // Copyright 2022 OpsMx, Inc 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package birger 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestConfig_applyDefaults(t *testing.T) { 24 tests := []struct { 25 name string 26 provided Config 27 want Config 28 }{ 29 { 30 "URL provided isn't overwritten", 31 Config{URL: "abc", Token: "abc"}, 32 Config{ 33 URL: "abc", 34 Token: "abc", 35 UpdateFrequencySeconds: defaultConfig.UpdateFrequencySeconds, 36 }, 37 }, { 38 "token isn't overwritten", 39 Config{Token: "xyz"}, 40 Config{ 41 URL: defaultConfig.URL, 42 Token: "xyz", 43 UpdateFrequencySeconds: defaultConfig.UpdateFrequencySeconds, 44 }, 45 }, { 46 "UpdateFrequencySeconds provided isn't overwritten", 47 Config{UpdateFrequencySeconds: 1234, Token: "abc"}, 48 Config{ 49 URL: defaultConfig.URL, 50 Token: "abc", 51 UpdateFrequencySeconds: 1234, 52 }, 53 }, 54 } 55 for _, tt := range tests { 56 t.Run(tt.name, func(t *testing.T) { 57 tt.provided.applyDefaults() 58 require.Equal(t, tt.want, tt.provided) 59 }) 60 } 61 }