tests all the things
This commit is contained in:
parent
68e74f2335
commit
10cd7eab15
9
db/db.go
9
db/db.go
@ -25,10 +25,7 @@ func DbConn(c data.HostDetails) *sql.DB {
|
|||||||
|
|
||||||
found, testUserName := data.ViperPgmConfig("test_user", "r")
|
found, testUserName := data.ViperPgmConfig("test_user", "r")
|
||||||
if found == true {
|
if found == true {
|
||||||
logger.Logger("[LOG] test requires containerized database or custom \"test_db\" in .pgm.yaml")
|
logger.Logger("[LOG] found test user 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")
|
|
||||||
}
|
}
|
||||||
psqlInfo = fmt.Sprintf("host=%s port=%d user=%s "+
|
psqlInfo = fmt.Sprintf("host=%s port=%d user=%s "+
|
||||||
"password=%s dbname=%s sslmode=disable",
|
"password=%s dbname=%s sslmode=disable",
|
||||||
@ -39,13 +36,14 @@ func DbConn(c data.HostDetails) *sql.DB {
|
|||||||
case testUserName:
|
case testUserName:
|
||||||
logger.Logger("[ERROR] go tests expects to connect with the docker compose database." +
|
logger.Logger("[ERROR] go tests expects to connect with the docker compose database." +
|
||||||
"[ERROR] run \"docker-compose up\" and re-run tests")
|
"[ERROR] run \"docker-compose up\" and re-run tests")
|
||||||
|
fmt.Println("local db is closed, please run docker-compose up")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
default:
|
default:
|
||||||
logger.Logger("[ERROR] db error: " + err.Error())
|
logger.Logger("[ERROR] db error: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
logger.Logger("[LOG] pinging db " + dbn)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err = db.PingContext(ctx)
|
err = db.PingContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -53,6 +51,7 @@ func DbConn(c data.HostDetails) *sql.DB {
|
|||||||
case testUserName:
|
case testUserName:
|
||||||
logger.Logger("[ERROR] db error, unable to ping: " + err.Error()+
|
logger.Logger("[ERROR] db error, unable to ping: " + err.Error()+
|
||||||
"[ERROR] ensure docker database is running and re-run tests")
|
"[ERROR] ensure docker database is running and re-run tests")
|
||||||
|
fmt.Println("local db is closed, please run docker-compose up")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
default:
|
default:
|
||||||
logger.Logger("[ERROR] db error: " + err.Error())
|
logger.Logger("[ERROR] db error: " + err.Error())
|
||||||
|
|||||||
@ -41,7 +41,6 @@ func Loader(t []string, s string, b string) error {
|
|||||||
var hostChoice host
|
var hostChoice host
|
||||||
var isT bool
|
var isT bool
|
||||||
isT = setTest(s)
|
isT = setTest(s)
|
||||||
logger.Logger("[LOG] is loader test: " + strconv.FormatBool(hostChoice.isTest))
|
|
||||||
hostChoice = host{60, s, t, 0, false, false, 0, b, isT}
|
hostChoice = host{60, s, t, 0, false, false, 0, b, isT}
|
||||||
if err := tea.NewProgram(hostChoice).Start(); err != nil {
|
if err := tea.NewProgram(hostChoice).Start(); err != nil {
|
||||||
if isT == true {
|
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
|
// Views return a string based on data in the host. That string which will be
|
||||||
// rendered to the terminal.
|
// rendered to the terminal.
|
||||||
func (m host) View() string {
|
func (m host) View() string {
|
||||||
logger.Logger("[LOG] view initialized")
|
|
||||||
var s string
|
var s string
|
||||||
if m.Quitting {
|
if m.Quitting {
|
||||||
logger.Logger("[LOG] leaving pgm")
|
logger.Logger("[LOG] leaving pgm")
|
||||||
@ -140,6 +138,7 @@ func (m host) View() string {
|
|||||||
s = choicesView(m)
|
s = choicesView(m)
|
||||||
} else {
|
} else {
|
||||||
tea.Quit()
|
tea.Quit()
|
||||||
|
logger.Logger("[LOG] " + m.File + " chosen")
|
||||||
LoadUi(m)
|
LoadUi(m)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
@ -225,7 +224,6 @@ func tick() tea.Cmd {
|
|||||||
// loads a yaml file into the correct format for consumption.
|
// loads a yaml file into the correct format for consumption.
|
||||||
// errs the pipeline step if there is not a configuration in this repository.
|
// errs the pipeline step if there is not a configuration in this repository.
|
||||||
func loadhost(c string, p *data.HostDetails) *data.HostDetails {
|
func loadhost(c string, p *data.HostDetails) *data.HostDetails {
|
||||||
logger.Logger("[LOG] file path string is: " + c)
|
|
||||||
cfg, err := ioutil.ReadFile(c)
|
cfg, err := ioutil.ReadFile(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Logger("[ERROR] unable to find this filepath: " + err.Error())
|
logger.Logger("[ERROR] unable to find this filepath: " + err.Error())
|
||||||
@ -240,6 +238,7 @@ func Screener(g data.HostDetails) {
|
|||||||
//var dbConn *sql.DB
|
//var dbConn *sql.DB
|
||||||
//var s interface{}
|
//var s interface{}
|
||||||
logger.Logger("[LOG] starting screen")
|
logger.Logger("[LOG] starting screen")
|
||||||
|
os.Exit(0)
|
||||||
//
|
//
|
||||||
//found, s := data.ViperScrConfig("userSessions", "r")
|
//found, s := data.ViperScrConfig("userSessions", "r")
|
||||||
//mapstructure.Decode(s, &scn)
|
//mapstructure.Decode(s, &scn)
|
||||||
|
|||||||
28
main_test.go
28
main_test.go
@ -1,11 +1,13 @@
|
|||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"os"
|
"os"
|
||||||
"pgm/config"
|
"pgm/config"
|
||||||
"pgm/data"
|
"pgm/data"
|
||||||
|
"pgm/db"
|
||||||
"pgm/loader"
|
"pgm/loader"
|
||||||
"pgm/logger"
|
"pgm/logger"
|
||||||
"testing"
|
"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) {
|
//func TestScreener(t *testing.T) {
|
||||||
// t.Parallel()
|
// t.Parallel()
|
||||||
// var p data.HostDetails
|
// var p data.HostDetails
|
||||||
@ -143,6 +166,11 @@ func TestViperScnConfig(t *testing.T) {
|
|||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
type connTest struct {
|
||||||
|
u string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
type viperScnReturn struct {
|
type viperScnReturn struct {
|
||||||
t string
|
t string
|
||||||
want string
|
want string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user