Files
Gokapi/cmd/gokapi/Main_test.go
T
2021-06-24 13:34:53 +02:00

50 lines
1.1 KiB
Go

// +build !integration
// +build test
package main
import (
"Gokapi/internal/test"
"Gokapi/internal/test/testconfiguration"
"os"
"testing"
)
func TestMain(m *testing.M) {
testconfiguration.Create(false)
exitVal := m.Run()
testconfiguration.Delete()
os.Exit(exitVal)
}
func TestParseFlags(t *testing.T) {
os.Args = []string{"gokapi", "--version", "--reset-pw", "-create-ssl"}
flags := parseFlags()
test.IsEqualBool(t, flags.showVersion, true)
test.IsEqualBool(t, flags.resetPw, true)
test.IsEqualBool(t, flags.createSsl, true)
os.Args = []string{"gokapi", "--reset-pw", "-create-ssl"}
flags = parseFlags()
test.IsEqualBool(t, flags.showVersion, false)
test.IsEqualBool(t, flags.resetPw, true)
test.IsEqualBool(t, flags.createSsl, true)
}
func TestShowVersion(t *testing.T) {
showVersion(flags{})
osExit = test.ExitCode(t, 0)
showVersion(flags{showVersion: true})
}
func TestNoResetPw(t *testing.T) {
resetPassword(flags{})
}
func TestCreateSsl(t *testing.T) {
test.FileDoesNotExist(t, "test/ssl.key")
createSsl(flags{})
test.FileDoesNotExist(t, "test/ssl.key")
createSsl(flags{createSsl: true})
test.FileExists(t, "test/ssl.key")
}