github.com/pavlo67/common@v0.5.3/common/config/test/cfg_test.go (about) 1 package cfg 2 3 //import ( 4 // "log" 5 // "os" 6 // "testing" 7 // 8 // "github.com/pavlo67/common/common/config" 9 // "github.com/pavlo67/common/common/filelib" 10 // 11 // "github.com/stretchr/testify/require" 12 //) 13 // 14 //func TestMain(m *testing.M) { 15 // if err := os.Setenv("ENV", "test"); err != nil { 16 // log.Fatalln("No test environment!!!") 17 // } 18 // os.Exit(m.Run()) 19 //} 20 // 21 //func TestReadFile(t *testing.T) { 22 // 23 // ExpectedStrings := map[string]string{ 24 // "test1": "1.000", 25 // "test2": "test2", 26 // } 27 // 28 // ExpectedFlags := map[string]bool{ 29 // "debug": true, 30 // } 31 // 32 // ExpectedMysqls := map[string]config.Access{ 33 // "notebook": { 34 // Host: "localhost", 35 // Port: 3306, 36 // User: "root", 37 // Pass: "", 38 // Path: "notebook_go_test", 39 // }, 40 // } 41 // 42 // //ExpectedIndex := map[string]serverhttp_jschmhr.ComponentsIndex{ 43 // // "main": { 44 // // EndpointsConfig: map[string]serverhttp_jschmhr.Endpoint{ 45 // // "ep1": {Method: "GET", LocalPath: "/"}, 46 // // }, 47 // // Listeners: map[string]serverhttp_jschmhr.Listener{ 48 // // "lst1": {Label: "id1"}, 49 // // }, 50 // // }, 51 // //} 52 // 53 // cfg, err := config.Get("cfg_test.json5") 54 // if err != nil { 55 // t.Fatal(err) 56 // } 57 // 58 // for k, es := range ExpectedStrings { 59 // s, errs := cfg.String(k, nil) 60 // if len(errs) > 0 { 61 // log.Fatalf("unexpected errs (%v) for string key: %s", errs, k) 62 // } 63 // require.Equal(t, s, es, "bad string for key: "+k) 64 // 65 // kUnexp := k + "unexpected" 66 // _, errs = cfg.String(kUnexp, nil) 67 // if len(errs) < 1 { 68 // log.Fatalf("no expected errs for string key: %s", kUnexp) 69 // } 70 // } 71 // 72 // for k, ef := range ExpectedFlags { 73 // f, errs := cfg.Bool(k, nil) 74 // if len(errs) > 0 { 75 // log.Fatalf("unexpected errs (%v) for bool flag key: %s", errs, k) 76 // } 77 // require.Equal(t, f, ef, "bad bool flag for key: "+k) 78 // 79 // kUnexp := k + "unexpected" 80 // _, errs = cfg.Bool(kUnexp, nil) 81 // if len(errs) < 1 { 82 // log.Fatalf("no expected errs for bool flag key: %s", kUnexp) 83 // } 84 // } 85 // 86 // for k, emc := range ExpectedMysqls { 87 // mc, errs := cfg.MySQL(k, nil) 88 // if len(errs) > 0 { 89 // log.Fatalf("unexpected errs (%v) for mysql key: %s", errs, k) 90 // } 91 // require.Equal(t, mc, emc, "bad mysql credentials for key: "+k) 92 // 93 // kUnexp := k + "unexpected" 94 // _, errs = cfg.MySQL(kUnexp, nil) 95 // if len(errs) < 1 { 96 // log.Fatalf("no expected errs for mysql credentials key: %s", kUnexp) 97 // } 98 // } 99 // 100 //}