add more test for id package

This commit is contained in:
Matthew Rich 2024-08-17 18:19:22 -07:00
parent 3086885655
commit dfd2a00541
2 changed files with 19 additions and 2 deletions

View File

@ -34,9 +34,10 @@ func (i ID) Extension() (exttype string, fileext string) {
if numberOfElements > 2 { if numberOfElements > 2 {
exttype = elements[numberOfElements - 2] exttype = elements[numberOfElements - 2]
fileext = elements[numberOfElements - 1] fileext = elements[numberOfElements - 1]
} else {
exttype = elements[numberOfElements - 1]
} }
exttype = elements[numberOfElements - 1]
} }
return return exttype, fileext
} }

View File

@ -34,6 +34,22 @@ func TestID(t *testing.T) {
assert.Equal(t, "", fileext) assert.Equal(t, "", fileext)
} }
func TestIDExt(t *testing.T) {
for _, v := range []struct { File ID
ExpectedExt string
ExpectedType string }{
{ File: "file:///tmp/foo/bar/baz.txt", ExpectedExt: "", ExpectedType: "txt" },
{ File: "file:///tmp/foo/bar/baz.txt.gz", ExpectedExt: "gz", ExpectedType: "txt" },
{ File: "file:///tmp/foo/bar/baz.quuz.txt.gz", ExpectedExt: "gz", ExpectedType: "txt" },
} {
u := v.File.Parse()
assert.Equal(t, "file", u.Scheme)
filetype, fileext := v.File.Extension()
assert.Equal(t, v.ExpectedType, filetype)
assert.Equal(t, v.ExpectedExt, fileext)
}
}
func TestSetID(t *testing.T) { func TestSetID(t *testing.T) {
var file ID = ID(fmt.Sprintf("file://%s", TempDir)) var file ID = ID(fmt.Sprintf("file://%s", TempDir))
u := file.Parse() u := file.Parse()