GitRepositoryManager/internal/echo/echo_test.go

152 lines
3.0 KiB
Go
Raw Permalink Normal View History

package echo
import (
"fmt"
"os"
"testing"
)
type ExpectedMessageTester struct {
expectedMessage string
}
func (emt ExpectedMessageTester) Write(p []byte) (n int, err error) {
msg := string(p)
if msg != emt.expectedMessage {
return 0, fmt.Errorf("expected to get \"%v\", instead of this got \"%v\"", msg, emt.expectedMessage)
}
return 0, nil
}
func TestOverwriteColor(t *testing.T) {
Color(false)
if useColor {
t.Error("Expected that \"useColor\" will be false")
}
Color(true)
if !useColor {
t.Error("Expected that \"useColor\" will be true")
}
}
func TestOverwriteWriter(t *testing.T) {
Output(os.Stderr)
if output != os.Stderr {
t.Error("Expected to receive addresses on os.Stderr")
}
Output(os.Stdout)
if output != os.Stdout {
t.Error("Expected to receive addresses on os.Stdout")
}
}
func TestErrorfMsgWithoutColor(t *testing.T) {
useColor = false
output = ExpectedMessageTester{
expectedMessage: "Error: test message\n",
}
err := ErrorfMsg("test message")
if err != nil {
t.Error(err)
}
}
func TestErrorfMsgWithColor(t *testing.T) {
useColor = true
output = ExpectedMessageTester{
expectedMessage: "\033[31mError:\033[0m test message\n",
}
err := ErrorfMsg("test message")
if err != nil {
t.Error(err)
}
}
func TestInfoMsgFWithoutColor(t *testing.T) {
useColor = false
output = ExpectedMessageTester{
expectedMessage: "Info: test message\n",
}
err := InfoFMsg("test message")
if err != nil {
t.Error(err)
}
}
func TestInfoMsgFWithColor(t *testing.T) {
useColor = true
output = ExpectedMessageTester{
expectedMessage: "\033[34mInfo:\033[0m test message\n",
}
err := InfoFMsg("test message")
if err != nil {
t.Error(err)
}
}
func TestGreenMessageWithoutColor(t *testing.T) {
useColor = false
output = ExpectedMessageTester{
expectedMessage: "test message\n",
}
err := GreenMessageF("test message")
if err != nil {
t.Error(err)
}
}
func TestGreenMessageWithColor(t *testing.T) {
useColor = true
output = ExpectedMessageTester{
expectedMessage: "\033[32mtest message\033[0m\n",
}
err := GreenMessageF("test message")
if err != nil {
t.Error(err)
}
}
func TestYellowMessageWithout(t *testing.T) {
useColor = false
output = ExpectedMessageTester{
expectedMessage: "test message\n",
}
err := YellowMessageF("test message")
if err != nil {
t.Error(err)
}
}
func TestYellowMessageWithColor(t *testing.T) {
useColor = true
output = ExpectedMessageTester{
expectedMessage: "\033[33mtest message\033[0m\n",
}
err := YellowMessageF("test message")
if err != nil {
t.Error(err)
}
}
func TestRedMessageWithout(t *testing.T) {
useColor = false
output = ExpectedMessageTester{
expectedMessage: "test message\n",
}
err := RedMessageF("test message")
if err != nil {
t.Error(err)
}
}
func TestRedMessageWithColor(t *testing.T) {
useColor = true
output = ExpectedMessageTester{
expectedMessage: "\033[31mtest message\033[0m\n",
}
err := RedMessageF("test message")
if err != nil {
t.Error(err)
}
}