pgm/main_test.go
2020-10-24 15:42:13 -05:00

63 lines
1.2 KiB
Go

package main_test
import (
"fmt"
"github.com/spf13/viper"
"os"
"pgm/config"
"pgm/logger"
"testing"
)
// init should always return true
// init will not write incorrect values to file
func TestInit(t *testing.T) {
t.Parallel()
var cfg string
testCases := []initTests{
{a: "junk", b: "notreal", c: "failingonpurpose", want: true},
{a: "test_host_dir", b: "test_screen_dr", c: "test_log_dir", want: true},
}
cfg, err := os.UserHomeDir()
if err != nil {
logger.Logger("failed to find home dir " + err.Error())
fmt.Println("an error was encountered and logged")
os.Exit(0)
}
for _, tc := range testCases {
got := config.IsInit(tc.a, tc.b, tc.c, cfg + "/.pgm.yml")
if tc.want != got {
t.Errorf("want %t, got %t", tc.want, got)
}
}
}
func TestLogs(t *testing.T) {
t.Parallel()
var s string
var want bool = true
s = "test"
got := logger.Logger(s)
if want != got {
t.Errorf("want %t, got %t", want, got)
}
}
func TestLoadConfig(t *testing.T) {
t.Parallel()
var v *viper.Viper
var want error = nil
v, got := config.ReadConfig()
_ = v
if want != got {
t.Error("load config reaturned a non nil error")
}
}
type initTests struct {
a, b, c string
want bool
}