mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
When unrecognised extensions are passed, FormatStringFromFilename defaults to 'yaml' (as handled in pkg/yqlib/format.go and tested in pkg/yqlib/format_test.go). This updates the test expectation in test/format_test.go for 'file.unknown' to 'yaml' so that go test ./test passes.
37 lines
772 B
Go
37 lines
772 B
Go
package test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mikefarah/yq/v4/pkg/yqlib"
|
|
)
|
|
|
|
// only test format detection based on filename extension
|
|
func TestFormatStringFromFilename(t *testing.T) {
|
|
cases := []struct {
|
|
filename string
|
|
expected string
|
|
}{
|
|
// filenames that have extensions
|
|
{"file.yaml", "yaml"},
|
|
{"FILE.JSON", "json"},
|
|
{"file.properties", "properties"},
|
|
{"file.xml", "xml"},
|
|
{"file.unknown", "yaml"},
|
|
|
|
// filenames without extensions
|
|
{"file", "yaml"},
|
|
{"a.dir/file", "yaml"},
|
|
{"file.", "yaml"},
|
|
{".", "yaml"},
|
|
{"", "yaml"},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
result := yqlib.FormatStringFromFilename(c.filename)
|
|
if result != c.expected {
|
|
t.Errorf("FormatStringFromFilename(%q) = %q, wanted: %q", c.filename, result, c.expected)
|
|
}
|
|
}
|
|
}
|