You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.4 KiB
66 lines
1.4 KiB
3 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestTrimFinalNewline(t *testing.T) {
|
||
|
trimmed := trimFinalNewline([]byte("foo\n"))
|
||
|
if trimmed != "foo" {
|
||
|
t.Fatalf("failed to trimmed new line from 'foo\\n'")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestTrimAllNewlines(t *testing.T) {
|
||
|
trimmed := trimAllNewlines("\nfoo\n")
|
||
|
if trimmed != "foo" {
|
||
|
t.Fatalf("failed to trimmed new line from '\\nfoo\\n'")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestParseMtype(t *testing.T) {
|
||
|
mtype := "os/directory"
|
||
|
ftype, stype, err := parseMtype(mtype)
|
||
|
if ftype != "os" || stype != "directory" {
|
||
|
t.Fatalf("unable to parse %s", mtype)
|
||
|
}
|
||
|
|
||
|
mtype = "image/gif; charset=utf-8"
|
||
|
ftype, stype, err = parseMtype(mtype)
|
||
|
if err != nil {
|
||
|
t.Fatalf("failed to parse %s", mtype)
|
||
|
}
|
||
|
if ftype != "image" || stype != "gif" {
|
||
|
t.Fatalf("unable to parse %s", mtype)
|
||
|
}
|
||
|
|
||
|
mtype = "notamimetype"
|
||
|
ftype, stype, err = parseMtype(mtype)
|
||
|
if err == nil {
|
||
|
t.Fatalf("failed to error out correctly parsing %s", mtype)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestGetLogFile(t *testing.T) {
|
||
|
f, err := getLogFile()
|
||
|
if err != nil {
|
||
|
t.Fatalf("failed to create log file, saw: %s", err)
|
||
|
}
|
||
|
|
||
|
if !strings.Contains(f.Name(), "distribusi-go") {
|
||
|
t.Fatalf("log file named incorrectly: %s", f.Name())
|
||
|
}
|
||
|
|
||
|
absPath, err := filepath.Abs(f.Name())
|
||
|
if err != nil {
|
||
|
t.Fatalf("failed to read absoluate path of %s", f.Name())
|
||
|
}
|
||
|
|
||
|
if err := os.Remove(absPath); err != nil {
|
||
|
t.Fatalf("unable to remove %s", absPath)
|
||
|
}
|
||
|
}
|