package nfs_test import ( "bytes" "git.noahlan.cn/noahlan/ntool/nfs" "git.noahlan.cn/noahlan/ntool/ntest/assert" "testing" ) func TestMimeType(t *testing.T) { assert.Eq(t, "", nfs.MimeType("")) assert.Eq(t, "", nfs.MimeType("not-exist")) assert.Eq(t, "text/plain; charset=utf-8", nfs.MimeType("testdata/mimetext.txt")) buf := new(bytes.Buffer) buf.Write([]byte("\xFF\xD8\xFF")) assert.Eq(t, "image/jpeg", nfs.ReaderMimeType(buf)) buf.Reset() buf.Write([]byte("text")) assert.Eq(t, "text/plain; charset=utf-8", nfs.ReaderMimeType(buf)) buf.Reset() buf.Write([]byte("")) assert.Eq(t, "", nfs.ReaderMimeType(buf)) buf.Reset() assert.False(t, nfs.IsImageFile("testdata/test.txt")) assert.False(t, nfs.IsImageFile("testdata/not-exists")) } func TestTempDir(t *testing.T) { dir, err := nfs.TempDir("testdata", "temp.*") assert.NoErr(t, err) assert.True(t, nfs.IsDir(dir)) assert.NoErr(t, nfs.Remove(dir)) } func TestSplitPath(t *testing.T) { dir, file := nfs.SplitPath("/path/to/dir/some.txt") assert.Eq(t, "/path/to/dir/", dir) assert.Eq(t, "some.txt", file) } func TestToAbsPath(t *testing.T) { assert.Eq(t, "", nfs.ToAbsPath("")) assert.Eq(t, "/path/to/dir/", nfs.ToAbsPath("/path/to/dir/")) assert.Neq(t, "~/path/to/dir", nfs.ToAbsPath("~/path/to/dir")) assert.Neq(t, ".", nfs.ToAbsPath(".")) assert.Neq(t, "..", nfs.ToAbsPath("..")) assert.Neq(t, "./", nfs.ToAbsPath("./")) assert.Neq(t, "../", nfs.ToAbsPath("../")) } func TestSlashPath(t *testing.T) { assert.Eq(t, "/path/to/dir", nfs.SlashPath("/path/to/dir")) assert.Eq(t, "/path/to/dir", nfs.UnixPath("/path/to/dir")) assert.Eq(t, "/path/to/dir", nfs.UnixPath("\\path\\to\\dir")) }