jx/internal/resource/resource_test.go
Matthew Rich e695278d0c
All checks were successful
Declarative Tests / test (push) Successful in 48s
go fmt
2024-03-25 13:31:06 -07:00

47 lines
906 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
import (
"context"
_ "fmt"
"github.com/stretchr/testify/assert"
"log"
"os"
"path/filepath"
"testing"
)
var TempDir string
func TestMain(m *testing.M) {
var err error
TempDir, err = os.MkdirTemp("", "testresourcefile")
if err != nil || TempDir == "" {
log.Fatal(err)
}
rc := m.Run()
os.RemoveAll(TempDir)
os.Exit(rc)
}
func TestNewResource(t *testing.T) {
resourceUri := "file://foo"
testFile := NewResource(resourceUri)
assert.NotNil(t, testFile)
assert.Equal(t, "foo", testFile.(*File).Path)
}
func TestResolveId(t *testing.T) {
testFile := NewResource("file://../../README.md")
assert.NotNil(t, testFile)
absolutePath, e := filepath.Abs("../../README.md")
assert.Nil(t, e)
testFile.ResolveId(context.Background())
assert.Equal(t, absolutePath, testFile.(*File).Path)
}