jx/internal/fan/jx_test.go
Matthew Rich c34a76981e
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
move source/target converters to fan pkg
2024-09-19 08:03:23 +00:00

47 lines
1.6 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package fan
import (
"github.com/stretchr/testify/assert"
"testing"
"decl/internal/codec"
"decl/internal/folio"
"decl/internal/data"
"net/url"
)
func TestNewJxSource(t *testing.T) {
s := NewJxFile()
assert.NotNil(t, s)
}
func TestJxSetURI(t *testing.T) {
for _,v := range []struct{ url string; expectedformat codec.Format; expecteduri string }{
{ url: "file://foo", expectedformat: codec.FormatYaml, expecteduri: "file://foo" },
{ url: "json://foo", expectedformat: codec.FormatJson, expecteduri: "file://foo?format=json" },
{ url: "yaml://foo", expectedformat: codec.FormatYaml, expecteduri: "file://foo?format=yaml" },
{ url: "file://foo?format=json", expectedformat: codec.FormatJson, expecteduri: "file://foo?format=json" },
{ url: "file://foo.jx.json", expectedformat: codec.FormatJson, expecteduri: "file://foo.jx.json" },
{ url: "file://foo.jx.json.gz", expectedformat: codec.FormatJson, expecteduri: "file://foo.jx.json.gz" },
{ url: "https://foo.jx.json.gz", expectedformat: codec.FormatJson, expecteduri: "https://foo.jx.json.gz" },
} {
j := NewJxFile()
assert.NotNil(t, j)
u,_ := url.Parse(v.url)
j.SetURI(u)
assert.Equal(t, v.expectedformat, j.Format)
assert.Equal(t, v.expecteduri, string(j.Uri))
}
}
func TestJxFactory(t *testing.T) {
converter, err := folio.DocumentRegistry.ConverterTypes.New("json://-")
assert.Nil(t, err)
assert.NotNil(t, converter)
assert.Equal(t, data.TypeName("jx"), converter.Type())
jxfile := converter.(*JxFile)
assert.Equal(t, "-", jxfile.Path)
assert.Equal(t, codec.FormatJson, jxfile.Format)
}