github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/config/configuration_test.go (about) 1 // Copyright 2023 IAC. All Rights Reserved. 2 3 // 4 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 7 // you may not use this file except in compliance with the License. 8 9 // You may obtain a copy of the License at 10 11 // 12 13 // http://www.apache.org/licenses/LICENSE-2.0 14 15 // 16 17 // Unless required by applicable law or agreed to in writing, software 18 19 // distributed under the License is distributed on an "AS IS" BASIS, 20 21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 23 // See the License for the specific language governing permissions and 24 25 // limitations under the License. 26 27 package config 28 29 import ( 30 "reflect" 31 "testing" 32 ) 33 34 func TestLoadConfig(t *testing.T) { 35 type Database struct { 36 Host string 37 Port int 38 } 39 40 type Config struct { 41 Database Database 42 } 43 44 tests := []struct { 45 name string 46 want *Config 47 wantErr bool 48 }{ 49 { 50 name: "Test Case 1", 51 want: &Config{ 52 Database: Database{ 53 Host: "localhost", 54 Port: 5432, 55 }, 56 }, 57 wantErr: false, 58 }, 59 } 60 for _, tt := range tests { 61 t.Run(tt.name, func(t *testing.T) { 62 got, err := LoadConfig() 63 if (err != nil) != tt.wantErr { 64 t.Errorf("LoadConfig() error = %v, wantErr %v", err, tt.wantErr) 65 return 66 } 67 if !reflect.DeepEqual(got, tt.want) { 68 t.Errorf("LoadConfig() = %v, want %v", got, tt.want) 69 } 70 }) 71 } 72 } 73 74 func TestLoadGlobalConfig(t *testing.T) { 75 tests := []struct { 76 name string 77 want *GlobalConfig 78 wantErr bool 79 }{ 80 // TODO: Add test cases. 81 { 82 name: "Test Case 1", 83 want: &GlobalConfig{ 84 InstanceName: "", 85 }, 86 wantErr: false, 87 }, 88 } 89 for _, tt := range tests { 90 t.Run(tt.name, func(t *testing.T) { 91 got, err := LoadGlobalConfig() 92 if (err != nil) != tt.wantErr { 93 t.Errorf("LoadGlobalConfig() error = %v, wantErr %v", err, tt.wantErr) 94 return 95 } 96 if !reflect.DeepEqual(got, tt.want) { 97 t.Errorf("LoadGlobalConfig() = %v, want %v", got, tt.want) 98 } 99 }) 100 } 101 102 }