jx/internal/identifier/id_test.go

45 lines
821 B
Go
Raw Normal View History

2024-08-15 15:12:42 +00:00
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. 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 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)
}