Przeglądaj źródła

config for test is separated and testMain is ready

tags/v0.5
patrick 5 lat temu
rodzic
commit
a2ec649a69
3 zmienionych plików z 34 dodań i 2 usunięć
  1. +11
    -2
      config.go
  2. +11
    -0
      config.test.json
  3. +12
    -0
      main_test.go

+ 11
- 2
config.go Wyświetl plik

var Config AppConfig var Config AppConfig


func readConfig() error { func readConfig() error {
log.Printf("Read configration from config.json")
body, err := ioutil.ReadFile("config.json")
return readConfigFile("config.json")
}

func readConfigFile(file string) error {

log.Printf("Read configration from %s", file)
body, err := ioutil.ReadFile(file)
if err != nil { if err != nil {
log.Fatal("Fatal error Cannot read config ..") log.Fatal("Fatal error Cannot read config ..")
return err return err
fmt.Println(string(j)) fmt.Println(string(j))
return err return err
} }

func readConfigForTest() error {
return readConfigFile("config.test.json")
}

+ 11
- 0
config.test.json Wyświetl plik

{
"Rpn": {
"Url" : "https://deposit.paylomo.net/pay.php?r=payEasy",
"UrlTest" : "https://deposit-mac.chinapaytech.com/pay.php?r=payEasy",
"MD5P2P" : "370296119874502",
"MD5FAT" : "207841502473198"
},
"LeanWork" :{
"MD5Key" : "492815086935204"
}
}

+ 12
- 0
main_test.go Wyświetl plik

package main

import (
"os"
"testing"
)

func TestMain(m *testing.M) {
// call flag.Parse() here if TestMain uses flags
readConfigForTest()
os.Exit(m.Run())
}

Ładowanie…
Anuluj
Zapisz