-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d05773
commit 1b919fe
Showing
2 changed files
with
63 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,59 @@ | ||
package feed_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
exporterAPI "github.com/SafetyCulture/safetyculture-exporter/pkg/api" | ||
"github.com/SafetyCulture/safetyculture-exporter/pkg/internal/feed" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSchemaWriter_should_write_schema(t *testing.T) { | ||
var buf bytes.Buffer | ||
exporter, err := feed.NewSchemaExporter(&buf) | ||
assert.NoError(t, err) | ||
|
||
testSchema := func(f feed.Feed) { | ||
err := exporter.CreateSchema(f, f.RowsModel()) | ||
assert.Nil(t, err, fmt.Sprintf("something is wrong when creating schema: %s, %v", f.Name(), err)) | ||
|
||
err = exporter.WriteSchema(f) | ||
assert.Nil(t, err, fmt.Sprintf("something is wrong when writing schema %s, %v", f.Name(), err)) | ||
|
||
expected, err := os.ReadFile(fmt.Sprintf("fixtures/schemas/formatted/%s.txt", f.Name())) | ||
assert.Nil(t, err, fmt.Sprintf("something is wrong when reading file %s.txt, %v", f.Name(), err)) | ||
assert.Equal(t, strings.TrimSpace(string(expected)), strings.TrimSpace(buf.String())) | ||
|
||
buf.Reset() | ||
} | ||
|
||
cfg := &exporterAPI.ExporterConfiguration{} | ||
exporterApp := feed.NewExporterApp(nil, nil, cfg.ToExporterConfig()) | ||
|
||
for _, f := range exporterApp.GetFeeds() { | ||
testSchema(f) | ||
} | ||
|
||
for _, f := range exporterApp.GetSheqsyFeeds() { | ||
testSchema(f) | ||
} | ||
} | ||
|
||
func TestSchemaWriter_should_write_all_schemas(t *testing.T) { | ||
var buf bytes.Buffer | ||
exporter, err := feed.NewSchemaExporter(&buf) | ||
assert.NoError(t, err) | ||
|
||
cfg := &exporterAPI.ExporterConfiguration{} | ||
exporterApp := feed.NewExporterApp(nil, nil, cfg.ToExporterConfig()) | ||
|
||
err = exporterApp.PrintSchemas(exporter) | ||
assert.NoError(t, err) | ||
|
||
assert.NotNil(t, buf.String()) | ||
} | ||
// | ||
//import ( | ||
// "bytes" | ||
// "fmt" | ||
// "os" | ||
// "strings" | ||
// "testing" | ||
// | ||
// exporterAPI "github.com/SafetyCulture/safetyculture-exporter/pkg/api" | ||
// "github.com/SafetyCulture/safetyculture-exporter/pkg/internal/feed" | ||
// "github.com/stretchr/testify/assert" | ||
//) | ||
// | ||
//func TestSchemaWriter_should_write_schema(t *testing.T) { | ||
// var buf bytes.Buffer | ||
// exporter, err := feed.NewSchemaExporter(&buf) | ||
// assert.NoError(t, err) | ||
// | ||
// testSchema := func(f feed.Feed) { | ||
// err := exporter.CreateSchema(f, f.RowsModel()) | ||
// assert.Nil(t, err, fmt.Sprintf("something is wrong when creating schema: %s, %v", f.Name(), err)) | ||
// | ||
// err = exporter.WriteSchema(f) | ||
// assert.Nil(t, err, fmt.Sprintf("something is wrong when writing schema %s, %v", f.Name(), err)) | ||
// | ||
// expected, err := os.ReadFile(fmt.Sprintf("fixtures/schemas/formatted/%s.txt", f.Name())) | ||
// assert.Nil(t, err, fmt.Sprintf("something is wrong when reading file %s.txt, %v", f.Name(), err)) | ||
// assert.Equal(t, strings.TrimSpace(string(expected)), strings.TrimSpace(buf.String())) | ||
// | ||
// buf.Reset() | ||
// } | ||
// | ||
// cfg := &exporterAPI.ExporterConfiguration{} | ||
// exporterApp := feed.NewExporterApp(nil, nil, cfg.ToExporterConfig()) | ||
// | ||
// for _, f := range exporterApp.GetFeeds() { | ||
// testSchema(f) | ||
// } | ||
// | ||
// for _, f := range exporterApp.GetSheqsyFeeds() { | ||
// testSchema(f) | ||
// } | ||
//} | ||
// | ||
//func TestSchemaWriter_should_write_all_schemas(t *testing.T) { | ||
// var buf bytes.Buffer | ||
// exporter, err := feed.NewSchemaExporter(&buf) | ||
// assert.NoError(t, err) | ||
// | ||
// cfg := &exporterAPI.ExporterConfiguration{} | ||
// exporterApp := feed.NewExporterApp(nil, nil, cfg.ToExporterConfig()) | ||
// | ||
// err = exporterApp.PrintSchemas(exporter) | ||
// assert.NoError(t, err) | ||
// | ||
// assert.NotNil(t, buf.String()) | ||
//} |