diff options
author | Wisdom Omuya <deafgoat@gmail.com> | 2014-09-29 18:37:18 -0400 |
---|---|---|
committer | Wisdom Omuya <deafgoat@gmail.com> | 2014-09-29 18:37:18 -0400 |
commit | e133124bd1c154e1318df2c0c7f45ae14e088bf6 (patch) | |
tree | f00c41cde8ae30c3abbc0651ee26106da0cdb19c | |
parent | bb7c07907fd13dff2eb378ebfcc1e3beaf1e290a (diff) | |
download | mongo-e133124bd1c154e1318df2c0c7f45ae14e088bf6.tar.gz |
update import tests
Former-commit-id: 4edb7178f947a2fb382739b7aee6cf4dee918a39
-rw-r--r-- | src/github.com/mongodb/mongo-tools/mongoimport/mongoimport.go | 5 | ||||
-rw-r--r-- | src/github.com/mongodb/mongo-tools/mongoimport/mongoimport_test.go | 18 |
2 files changed, 12 insertions, 11 deletions
diff --git a/src/github.com/mongodb/mongo-tools/mongoimport/mongoimport.go b/src/github.com/mongodb/mongo-tools/mongoimport/mongoimport.go index f82d800aea7..763cd7f9449 100644 --- a/src/github.com/mongodb/mongo-tools/mongoimport/mongoimport.go +++ b/src/github.com/mongodb/mongo-tools/mongoimport/mongoimport.go @@ -10,6 +10,7 @@ import ( "gopkg.in/mgo.v2/bson" "io" "os" + "path/filepath" "reflect" "strings" ) @@ -139,8 +140,8 @@ func (mongoImport *MongoImport) ValidateSettings(args []string) error { } else { fileBaseName = args[0] } - lastDotIndex := strings.LastIndex(fileBaseName, ".") - if lastDotIndex != -1 { + fileBaseName = filepath.Base(fileBaseName) + if lastDotIndex := strings.LastIndex(fileBaseName, "."); lastDotIndex != -1 { fileBaseName = fileBaseName[0:lastDotIndex] } if err := util.ValidateCollectionName(fileBaseName); err != nil { diff --git a/src/github.com/mongodb/mongo-tools/mongoimport/mongoimport_test.go b/src/github.com/mongodb/mongo-tools/mongoimport/mongoimport_test.go index b83960ad9cb..b3162af582d 100644 --- a/src/github.com/mongodb/mongo-tools/mongoimport/mongoimport_test.go +++ b/src/github.com/mongodb/mongo-tools/mongoimport/mongoimport_test.go @@ -56,7 +56,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldNotBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldNotBeNil) }) Convey("an error should be thrown if an invalid type is given", func() { @@ -76,7 +76,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldNotBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldNotBeNil) }) Convey("an error should be thrown if neither --headerline is supplied "+ @@ -97,7 +97,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldNotBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldNotBeNil) }) Convey("no error should be thrown if --headerline is not supplied "+ @@ -119,7 +119,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldBeNil) }) Convey("no error should be thrown if no input type is supplied", @@ -140,7 +140,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldBeNil) }) Convey("no error should be thrown if --headerline is not supplied "+ @@ -162,7 +162,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldBeNil) }) Convey("an error should be thrown if no collection and no file is "+ @@ -183,7 +183,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldNotBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldNotBeNil) }) Convey("no error should be thrown if no collection but a file is "+ @@ -206,7 +206,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldBeNil) So(mongoImport.ToolOptions.Namespace.Collection, ShouldEqual, mongoImport.InputOptions.File) }) @@ -231,7 +231,7 @@ func TestMongoImportValidateSettings(t *testing.T) { InputOptions: inputOptions, IngestOptions: ingestOptions, } - So(mongoImport.ValidateSettings(), ShouldBeNil) + So(mongoImport.ValidateSettings([]string{}), ShouldBeNil) So(mongoImport.ToolOptions.Namespace.Collection, ShouldEqual, "input") }) |