mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 02:12:05 -05:00
Add more tests to general helper
This commit is contained in:
parent
1b91fec0ac
commit
9e688507a7
1 changed files with 42 additions and 0 deletions
|
@ -1,10 +1,52 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGuessType(t *testing.T) {
|
||||
for i, this := range []struct {
|
||||
in string
|
||||
expect string
|
||||
}{
|
||||
{"md", "markdown"},
|
||||
{"markdown", "markdown"},
|
||||
{"mdown", "markdown"},
|
||||
{"rst", "rst"},
|
||||
{"html", "html"},
|
||||
{"htm", "html"},
|
||||
{"excel", "unknown"},
|
||||
} {
|
||||
result := GuessType(this.in)
|
||||
if result != this.expect {
|
||||
t.Errorf("[%d] GuessType guessed wrong, expected %s, got %s", i, this.expect, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBytesToReader(t *testing.T) {
|
||||
asBytes := ReaderToBytes(strings.NewReader("Hello World!"))
|
||||
asReader := BytesToReader(asBytes)
|
||||
assert.Equal(t, []byte("Hello World!"), asBytes)
|
||||
assert.Equal(t, asBytes, ReaderToBytes(asReader))
|
||||
}
|
||||
|
||||
func TestStringToReader(t *testing.T) {
|
||||
asString := ReaderToString(strings.NewReader("Hello World!"))
|
||||
assert.Equal(t, "Hello World!", asString)
|
||||
asReader := StringToReader(asString)
|
||||
assert.Equal(t, asString, ReaderToString(asReader))
|
||||
}
|
||||
|
||||
func TestFindAvailablePort(t *testing.T) {
|
||||
addr, err := FindAvailablePort()
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, addr)
|
||||
assert.True(t, addr.Port > 0)
|
||||
}
|
||||
|
||||
func TestInStringArrayCaseSensitive(t *testing.T) {
|
||||
type test struct {
|
||||
input string
|
||||
|
|
Loading…
Reference in a new issue