github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/testloader.go (about) 1 // Ultimate Provisioner: UP cmd 2 // Copyright (c) 2019 Stephen Cheng and contributors 3 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 7 8 package tests 9 10 import ( 11 "fmt" 12 "github.com/spf13/viper" 13 //"github.com/upcmd/up/model" 14 "os" 15 "path" 16 "runtime" 17 ) 18 19 var ( 20 ymlroot *viper.Viper 21 RootDir, TestDataDir = getDirs() 22 ) 23 24 func getDirs() (string, string) { 25 _, filename, _, _ := runtime.Caller(1) 26 utilsDir := path.Dir(filename) 27 rootDir := path.Join(utilsDir, "..") 28 return rootDir, path.Join(rootDir, "./testdata/poc") 29 } 30 31 func MockLoadYml(path, filename string) *viper.Viper { 32 33 viper.AddConfigPath(".") //test in current directory as top priority then the configured path 34 viper.AddConfigPath(path) 35 viper.SetConfigType("yaml") 36 viper.SetConfigName(filename) 37 38 err := viper.ReadInConfig() 39 40 if err != nil { 41 fmt.Printf("yml file: %s/%s.yml not found...", path, filename) 42 fmt.Println("errored:", err.Error()) 43 os.Exit(3) 44 } 45 46 ymlroot = viper.GetViper() 47 return viper.GetViper() 48 49 } 50 51 //func GetNode(node string) model.Step { 52 // 53 // var step model.Step 54 // cfgEntry := ymlroot.Sub(node) 55 // 56 // err := cfgEntry.Unmarshal(&step) 57 // 58 // if err != nil { 59 // fmt.Println("unable to decode into struct:", err.Error()) 60 // } 61 // return step 62 //}