Skip to content

Commit f8d604a

Browse files
committed
Convert test/qa-tests/jstests/export/namespace_validation.js to Go
1 parent 6ef94ec commit f8d604a

2 files changed

Lines changed: 32 additions & 39 deletions

File tree

mongoexport/mongoexport_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,3 +487,35 @@ func TestBrokenPipe(t *testing.T) {
487487
args = append(args, "--db", dbName, "--collection", collName)
488488
testutil.AssertBrokenPipeHandled(t, exec.Command("go", args...))
489489
}
490+
491+
// TestExportNamespaceValidation verifies that mongoexport rejects invalid DB
492+
// names and accepts system collections (from namespace_validation.js).
493+
func TestExportNamespaceValidation(t *testing.T) {
494+
testtype.SkipUnlessTestType(t, testtype.IntegrationTestType)
495+
log.SetWriter(io.Discard)
496+
497+
for _, dbName := range []string{"test.bar", `test"bar`} {
498+
toolOptions, err := testutil.GetToolOptions()
499+
require.NoError(t, err)
500+
toolOptions.Namespace = &options.Namespace{DB: dbName, Collection: "foo"}
501+
_, err = New(Options{
502+
ToolOptions: toolOptions,
503+
OutputFormatOptions: &OutputFormatOptions{Type: "json", JSONFormat: "canonical"},
504+
InputOptions: &InputOptions{},
505+
})
506+
assert.Error(t, err, "db name %q should be rejected", dbName)
507+
}
508+
509+
toolOptions, err := testutil.GetToolOptions()
510+
require.NoError(t, err)
511+
toolOptions.Namespace = &options.Namespace{DB: "test", Collection: "system.foobar"}
512+
me, err := New(Options{
513+
ToolOptions: toolOptions,
514+
OutputFormatOptions: &OutputFormatOptions{Type: "json", JSONFormat: "canonical"},
515+
InputOptions: &InputOptions{},
516+
})
517+
assert.NoError(t, err, "system collection should be accepted")
518+
if me != nil {
519+
me.Close()
520+
}
521+
}

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

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

0 commit comments

Comments
 (0)