2024-09-19 08:11:57 +00:00
|
|
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
|
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
"net/url"
|
2024-10-16 17:26:42 +00:00
|
|
|
"decl/internal/folio"
|
2024-09-19 08:11:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewCommon(t *testing.T) {
|
2024-09-28 05:04:15 +00:00
|
|
|
c := NewCommon(TypeName("foo"), false)
|
2024-09-19 08:11:57 +00:00
|
|
|
assert.NotNil(t, c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommon(t *testing.T) {
|
2024-09-28 05:04:15 +00:00
|
|
|
expectedCommon := NewCommon(FileTypeName, false)
|
|
|
|
expectedCommon.resourceType = "file"
|
|
|
|
expectedCommon.parsedURI = &url.URL{ Scheme: "file", Path: "/tmp/foo"}
|
|
|
|
expectedCommon.Path = "/tmp/foo"
|
2024-10-16 17:26:42 +00:00
|
|
|
for _, v := range []struct{ uri folio.URI; expected *Common }{
|
2024-09-28 05:04:15 +00:00
|
|
|
{ uri: "file:///tmp/foo", expected: expectedCommon },
|
2024-09-19 08:11:57 +00:00
|
|
|
}{
|
2024-09-28 05:04:15 +00:00
|
|
|
|
|
|
|
c := NewCommon(FileTypeName, false)
|
2024-09-19 08:11:57 +00:00
|
|
|
c.resourceType = "file"
|
2024-10-16 17:26:42 +00:00
|
|
|
assert.Nil(t, c.SetParsedURI(v.uri.Parse()))
|
2024-09-28 05:04:15 +00:00
|
|
|
assert.Equal(t, v.expected.resourceType , c.resourceType)
|
2024-09-19 08:11:57 +00:00
|
|
|
assert.Equal(t, v.expected.Path, c.Path)
|
2024-09-28 05:04:15 +00:00
|
|
|
assert.Equal(t, v.expected.parsedURI.Scheme, c.parsedURI.Scheme)
|
|
|
|
assert.Equal(t, v.expected.parsedURI.Path, c.parsedURI.Path)
|
2024-09-19 08:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|