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:
parent
14b5cc4a8b
commit
7ad2619369
1 changed files with 39 additions and 0 deletions
39
cli_test.go
Normal file
39
cli_test.go
Normal 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)
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue