decentral1se
3 years ago
2 changed files with 79 additions and 16 deletions
@ -0,0 +1,65 @@ |
|||
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) |
|||
} |
|||
} |
Loading…
Reference in new issue