Skip to content

Commit 4ce922f

Browse files
committed
Convert test/qa-tests/jstests/export/no_data.js to Go
1 parent ce1b092 commit 4ce922f

3 files changed

Lines changed: 34 additions & 41 deletions

File tree

mongoexport/mongoexport_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func TestBrokenPipe(t *testing.T) {
489489
}
490490

491491
// TestExportNamespaceValidation verifies that mongoexport rejects invalid DB
492-
// names and accepts system collections (from namespace_validation.js).
492+
// names and accepts system collections.
493493
func TestExportNamespaceValidation(t *testing.T) {
494494
testtype.SkipUnlessTestType(t, testtype.IntegrationTestType)
495495
log.SetWriter(io.Discard)
@@ -519,3 +519,35 @@ func TestExportNamespaceValidation(t *testing.T) {
519519
me.Close()
520520
}
521521
}
522+
523+
// TestExportNoData verifies that exporting an empty collection succeeds, but
524+
// fails with --assertExists.
525+
func TestExportNoData(t *testing.T) {
526+
testtype.SkipUnlessTestType(t, testtype.IntegrationTestType)
527+
log.SetWriter(io.Discard)
528+
529+
toolOptions, err := testutil.GetToolOptions()
530+
require.NoError(t, err)
531+
toolOptions.Namespace = &options.Namespace{DB: "test", Collection: "mongoexport_no_data_test"}
532+
533+
me, err := New(Options{
534+
ToolOptions: toolOptions,
535+
OutputFormatOptions: &OutputFormatOptions{Type: "json", JSONFormat: "canonical"},
536+
InputOptions: &InputOptions{},
537+
})
538+
require.NoError(t, err)
539+
defer me.Close()
540+
var buf bytes.Buffer
541+
_, err = me.Export(&buf)
542+
assert.NoError(t, err, "export from empty collection should succeed")
543+
544+
me2, err := New(Options{
545+
ToolOptions: toolOptions,
546+
OutputFormatOptions: &OutputFormatOptions{Type: "json", JSONFormat: "canonical"},
547+
InputOptions: &InputOptions{AssertExists: true},
548+
})
549+
require.NoError(t, err)
550+
defer me2.Close()
551+
_, err = me2.Export(&buf)
552+
assert.Error(t, err, "export with --assertExists should fail on nonexistent collection")
553+
}

mongoimport/mongoimport_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,8 +2272,7 @@ func TestRoundTripLimit(t *testing.T) {
22722272
}
22732273

22742274
// TestRoundTripNestedFieldsCSV verifies that mongoexport correctly exports
2275-
// nested dotted field paths to CSV and that mongoimport restores them
2276-
// (from nested_fields_csv.js).
2275+
// nested dotted field paths to CSV and that mongoimport restores them.
22772276
func TestRoundTripNestedFieldsCSV(t *testing.T) {
22782277
testtype.SkipUnlessTestType(t, testtype.IntegrationTestType)
22792278

test/qa-tests/jstests/export/no_data.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)