github.com/SimplyVC/oasis_api_server/src@v0.0.0-20220105202803-ad2c5a67840e/config/config_test.go (about) 1 package config_test 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 8 "github.com/SimplyVC/oasis_api_server/src/config" 9 lgr "github.com/SimplyVC/oasis_api_server/src/logger" 10 ) 11 12 // Setting data to test with, valid and invalid path locations 13 const ( 14 mainConfigFile = "config/user_config_main.ini" 15 nodesFile = "config/user_config_nodes.ini" 16 mainFileFail = "test_config_main_fail.ini" 17 nodesFileFail = "test_config_nodes_fail.ini" 18 ) 19 20 func TestMain(m *testing.M) { 21 setup() 22 code := m.Run() 23 os.Exit(code) 24 } 25 26 func setup() { 27 os.Chdir("../") 28 29 // Set Logger that will be used by API through all packages 30 lgr.SetLogger(os.Stdout, os.Stdout, os.Stderr) 31 fmt.Printf("\033[1;36m%s\033[0m", "> Setup completed\n") 32 } 33 34 func teardown() { 35 fmt.Printf("\033[1;36m%s\033[0m", "> Teardown completed") 36 fmt.Printf("\n") 37 } 38 39 func TestLoadMainConfiguration_Success_1(t *testing.T) { 40 mainConf, _ := config.LoadMainConfiguration() 41 if mainConf == nil { 42 t.Errorf("Failed to load main config file from path.") 43 } 44 } 45 46 func TestLoadNodesConfig_Success_1(t *testing.T) { 47 nodesConf, _ := config.LoadNodesConfiguration() 48 if nodesConf == nil { 49 t.Errorf("Failed to load node config file from path.") 50 } 51 } 52 func TestLoadMainConfiguration_Success_2(t *testing.T) { 53 mainConf, _ := config.LoadNodesConfiguration() 54 if mainConf == nil { 55 t.Errorf("Failed to load main config file from path.") 56 } 57 mainConf_1 := config.GetMain() 58 if mainConf_1 == nil { 59 t.Errorf("Failed to load main config file from path.") 60 } 61 } 62 63 func TestLoadNodesConfig_Success_2(t *testing.T) { 64 nodesConf, _ := config.LoadNodesConfiguration() 65 if nodesConf == nil { 66 t.Errorf("Failed to load node config file from path.") 67 } 68 nodesConf_1 := config.GetNodes() 69 if nodesConf_1 == nil { 70 t.Errorf("Failed to load node config file from path.") 71 } 72 } 73 74 func TestLoadMainConfiguration_Failure_1(t *testing.T) { 75 config.SetMainFile(mainFileFail) 76 mainConf, _ := config.LoadMainConfiguration() 77 if mainConf != nil { 78 t.Errorf("Failed to not load main config file from path.") 79 } 80 } 81 82 func TestLoadNodesConfig_Failure_1(t *testing.T) { 83 config.SetNodesFile(nodesFileFail) 84 nodesConf, _ := config.LoadNodesConfiguration() 85 if nodesConf != nil { 86 t.Errorf("Failed to not load nodes file from path.") 87 } 88 }