diff --git a/db/db.go b/db/db.go index 49904fd..7881dac 100644 --- a/db/db.go +++ b/db/db.go @@ -25,10 +25,7 @@ func DbConn(c data.HostDetails) *sql.DB { found, testUserName := data.ViperPgmConfig("test_user", "r") if found == true { - logger.Logger("[LOG] test requires containerized database or custom \"test_db\" in .pgm.yaml") - } else { - logger.Logger("[LOG] no reserved username found in logfile, reset with a key \"test_user\"") - logger.Logger("[LOG] test requires containerized database or custom \"test_db\" in .pgm.yaml") + logger.Logger("[LOG] found test user in .pgm.yaml") } psqlInfo = fmt.Sprintf("host=%s port=%d user=%s "+ "password=%s dbname=%s sslmode=disable", @@ -39,13 +36,14 @@ func DbConn(c data.HostDetails) *sql.DB { case testUserName: logger.Logger("[ERROR] go tests expects to connect with the docker compose database." + "[ERROR] run \"docker-compose up\" and re-run tests") + fmt.Println("local db is closed, please run docker-compose up") os.Exit(1) default: logger.Logger("[ERROR] db error: " + err.Error()) } } - + logger.Logger("[LOG] pinging db " + dbn) ctx := context.Background() err = db.PingContext(ctx) if err != nil { @@ -53,6 +51,7 @@ func DbConn(c data.HostDetails) *sql.DB { case testUserName: logger.Logger("[ERROR] db error, unable to ping: " + err.Error()+ "[ERROR] ensure docker database is running and re-run tests") + fmt.Println("local db is closed, please run docker-compose up") os.Exit(1) default: logger.Logger("[ERROR] db error: " + err.Error()) diff --git a/loader/loader.go b/loader/loader.go index 1c832fe..4c586a6 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -41,7 +41,6 @@ func Loader(t []string, s string, b string) error { var hostChoice host var isT bool isT = setTest(s) - logger.Logger("[LOG] is loader test: " + strconv.FormatBool(hostChoice.isTest)) hostChoice = host{60, s, t, 0, false, false, 0, b, isT} if err := tea.NewProgram(hostChoice).Start(); err != nil { if isT == true { @@ -129,7 +128,6 @@ func (m host) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Views return a string based on data in the host. That string which will be // rendered to the terminal. func (m host) View() string { - logger.Logger("[LOG] view initialized") var s string if m.Quitting { logger.Logger("[LOG] leaving pgm") @@ -140,6 +138,7 @@ func (m host) View() string { s = choicesView(m) } else { tea.Quit() + logger.Logger("[LOG] " + m.File + " chosen") LoadUi(m) } return s @@ -225,7 +224,6 @@ func tick() tea.Cmd { // loads a yaml file into the correct format for consumption. // errs the pipeline step if there is not a configuration in this repository. func loadhost(c string, p *data.HostDetails) *data.HostDetails { - logger.Logger("[LOG] file path string is: " + c) cfg, err := ioutil.ReadFile(c) if err != nil { logger.Logger("[ERROR] unable to find this filepath: " + err.Error()) @@ -240,6 +238,7 @@ func Screener(g data.HostDetails) { //var dbConn *sql.DB //var s interface{} logger.Logger("[LOG] starting screen") + os.Exit(0) // //found, s := data.ViperScrConfig("userSessions", "r") //mapstructure.Decode(s, &scn) diff --git a/main_test.go b/main_test.go index bdf2e85..dae0757 100644 --- a/main_test.go +++ b/main_test.go @@ -1,11 +1,13 @@ package main_test import ( + "encoding/json" "fmt" "github.com/spf13/viper" "os" "pgm/config" "pgm/data" + "pgm/db" "pgm/loader" "pgm/logger" "testing" @@ -119,6 +121,27 @@ func TestViperScnConfig(t *testing.T) { } +func TestDbConn(t *testing.T) { + t.Parallel() + var h data.HostDetails + found, c := data.ViperPgmConfig("test_db", "r") + if found != true { + logger.Logger("[LOG] failed to find test_db in .pgm.yaml") + } + err := json.Unmarshal([]byte(c), &h) + if err != nil { + logger.Logger("[ERROR] db conn test failure: " + err.Error()) + } + got := db.DbConn(h) + err = got.Close() + if err != nil { + t.Errorf("sql function did not test correctly") + } + + +} + + //func TestScreener(t *testing.T) { // t.Parallel() // var p data.HostDetails @@ -143,6 +166,11 @@ func TestViperScnConfig(t *testing.T) { // //} +type connTest struct { + u string + +} + type viperScnReturn struct { t string want string