Skip to content

Commit bc03e95

Browse files
committed
Convert test/qa-tests/jstests/export/no_data.js to Go
1 parent 9519af2 commit bc03e95

3 files changed

Lines changed: 33 additions & 40 deletions

File tree

.ai-plans/2026-03-13/js-to-go-test-migration/plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ The mongoexport library API: create `mongoexport.MongoExport{Options: opts}`, th
272272

273273
- [x] **Step 11: Convert `namespace_validation.js`** (NEW) — `TestExportNamespaceValidation` in `mongoexport/mongoexport_test.go`: asserts `New()` errors on `test.bar` and `test"bar` as DB names, and succeeds on `system.foobar` as a collection name.
274274

275-
- [ ] **Step 12: Convert `no_data.js`** (EXTEND) — Add to `TestMongoExportTOOLS2174` or a new case: verify `--assertExists` flag returns an error for a collection that does not exist.
275+
- [x] **Step 12: Convert `no_data.js`** (EXTEND) — `TestExportNoData` in `mongoexport/mongoexport_test.go`: asserts export from nonexistent collection succeeds, and fails with `AssertExists: true`.
276276

277277
- [ ] **Step 13: Convert `pretty.js`** (NEW) — `TestExportPretty`: verify `--pretty` flag produces indented JSON output.
278278

mongoexport/mongoexport_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,35 @@ func TestExportNamespaceValidation(t *testing.T) {
484484
me.Close()
485485
}
486486
}
487+
488+
// TestExportNoData verifies that exporting an empty collection succeeds, but
489+
// fails with --assertExists (from no_data.js).
490+
func TestExportNoData(t *testing.T) {
491+
testtype.SkipUnlessTestType(t, testtype.IntegrationTestType)
492+
log.SetWriter(io.Discard)
493+
494+
toolOptions, err := testutil.GetToolOptions()
495+
require.NoError(t, err)
496+
toolOptions.Namespace = &options.Namespace{DB: "test", Collection: "mongoexport_no_data_test"}
497+
498+
me, err := New(Options{
499+
ToolOptions: toolOptions,
500+
OutputFormatOptions: &OutputFormatOptions{Type: "json", JSONFormat: "canonical"},
501+
InputOptions: &InputOptions{},
502+
})
503+
require.NoError(t, err)
504+
defer me.Close()
505+
var buf bytes.Buffer
506+
_, err = me.Export(&buf)
507+
assert.NoError(t, err, "export from empty collection should succeed")
508+
509+
me2, err := New(Options{
510+
ToolOptions: toolOptions,
511+
OutputFormatOptions: &OutputFormatOptions{Type: "json", JSONFormat: "canonical"},
512+
InputOptions: &InputOptions{AssertExists: true},
513+
})
514+
require.NoError(t, err)
515+
defer me2.Close()
516+
_, err = me2.Export(&buf)
517+
assert.Error(t, err, "export with --assertExists should fail on nonexistent collection")
518+
}

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

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

0 commit comments

Comments
 (0)