-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
beetle_test.go
50 lines (39 loc) · 1.07 KB
/
beetle_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2020 Clivern. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/clivern/beetle/core/module"
"github.com/clivern/beetle/pkg"
"github.com/drone/envsubst"
"github.com/spf13/viper"
)
var testingConfig = "config.testing.yml"
// TestMain test cases
func TestMain(t *testing.T) {
// LoadConfigFile
t.Run("LoadConfigFile", func(t *testing.T) {
fs := module.FileSystem{}
dir, _ := os.Getwd()
configFile := fmt.Sprintf("%s/%s", dir, testingConfig)
for {
if fs.FileExists(configFile) {
break
}
dir = filepath.Dir(dir)
configFile = fmt.Sprintf("%s/%s", dir, testingConfig)
}
t.Logf("Load Config File %s", configFile)
configUnparsed, _ := ioutil.ReadFile(configFile)
configParsed, _ := envsubst.EvalEnv(string(configUnparsed))
viper.SetConfigType("yaml")
viper.ReadConfig(bytes.NewBuffer([]byte(configParsed)))
pkg.Expect(t, viper.GetString("app.mode"), "test")
})
}