From dfd2a0054162412ad14d1800eac488197f022a96 Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Sat, 17 Aug 2024 18:19:22 -0700 Subject: [PATCH] add more test for id package --- internal/identifier/id.go | 5 +++-- internal/identifier/id_test.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/internal/identifier/id.go b/internal/identifier/id.go index 0cc8c34..e5888a9 100644 --- a/internal/identifier/id.go +++ b/internal/identifier/id.go @@ -34,9 +34,10 @@ func (i ID) Extension() (exttype string, fileext string) { if numberOfElements > 2 { exttype = elements[numberOfElements - 2] fileext = elements[numberOfElements - 1] + } else { + exttype = elements[numberOfElements - 1] } - exttype = elements[numberOfElements - 1] } - return + return exttype, fileext } diff --git a/internal/identifier/id_test.go b/internal/identifier/id_test.go index 8377ffc..d10da51 100644 --- a/internal/identifier/id_test.go +++ b/internal/identifier/id_test.go @@ -34,6 +34,22 @@ func TestID(t *testing.T) { 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) { var file ID = ID(fmt.Sprintf("file://%s", TempDir)) u := file.Parse()