// Copyright 2024 Matthew Rich . All rights reserved. package identifier import ( "github.com/stretchr/testify/assert" "testing" "fmt" "os" "log" ) var TempDir string func TestMain(m *testing.M) { var err error TempDir, err = os.MkdirTemp("", "testidentifier") if err != nil || TempDir == "" { log.Fatal(err) } rc := m.Run() os.RemoveAll(TempDir) os.Exit(rc) } func TestID(t *testing.T) { var file ID = ID(fmt.Sprintf("file://%s", TempDir)) u := file.Parse() assert.Equal(t, "file", u.Scheme) filetype, fileext := file.Extension() assert.Equal(t, "", filetype) 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() var setFile ID setFile.SetURL(u) assert.Equal(t, file, setFile) }