1
0
Fork 0
mirror of https://github.com/shouptech/tempgopher.git synced 2026-02-03 08:39:43 +00:00

Add CLI tests

This commit is contained in:
Emma 2018-10-26 10:12:22 -06:00
parent 14b5cc4a8b
commit 7ad2619369

39
cli_test.go Normal file
View file

@ -0,0 +1,39 @@
package main
import (
"bufio"
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_ReadInput(t *testing.T) {
// Test basic input
buf := bytes.NewBufferString("foobar\n")
reader := bufio.NewReader(buf)
resp := ReadInput(reader, "")
assert.Equal(t, "foobar", resp)
// Test default input
buf = bytes.NewBufferString("\n")
reader = bufio.NewReader(buf)
resp = ReadInput(reader, "default")
assert.Equal(t, "default", resp)
// Test that a panic occurred
buf = bytes.NewBufferString("")
reader = bufio.NewReader(buf)
assert.Panics(t, func() { ReadInput(reader, "") })
}
func Test_ParsePort(t *testing.T) {
// Test that 600 is parsed succesfully
port, err := ParsePort(":600")
assert.Equal(t, uint16(600), port)
assert.Equal(t, nil, err)
// Test failure
port, err = ParsePort("")
assert.NotEqual(t, nil, err)
}