feat: add generic file conversion sdk example
This commit is contained in:
25
sdk/go/examples/file-conversion/main_test.go
Normal file
25
sdk/go/examples/file-conversion/main_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestConvertCSV(t *testing.T) {
|
||||
out, err := convert(conversionInput{FileName: "records.csv", Content: "name,amount\nalpha,2\nbeta,3\n", TargetFormat: "json"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out.FileName != "records.json" || out.Format != "json" || out.Rows != 2 || out.Content != `[{"amount":"2","name":"alpha"},{"amount":"3","name":"beta"}]` {
|
||||
t.Fatalf("unexpected output: %+v", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertRejectsMalformedCSV(t *testing.T) {
|
||||
for _, in := range []conversionInput{
|
||||
{FileName: "records.csv", Content: "name,amount\nalpha\n", TargetFormat: "json"},
|
||||
{FileName: "records.csv", Content: "name,name\nalpha,beta\n", TargetFormat: "json"},
|
||||
{FileName: "records.csv", Content: "name,amount\nalpha,2\n", TargetFormat: "xml"},
|
||||
} {
|
||||
if _, err := convert(in); err == nil {
|
||||
t.Fatalf("malformed input accepted: %+v", in)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user