當前位置: 首頁>>代碼示例>>Golang>>正文


Golang testutil.VerifyTestType函數代碼示例

本文整理匯總了Golang中github.com/mongodb/mongo-tools/common/testutil.VerifyTestType函數的典型用法代碼示例。如果您正苦於以下問題:Golang VerifyTestType函數的具體用法?Golang VerifyTestType怎麽用?Golang VerifyTestType使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了VerifyTestType函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestJSCodeBSONToJSON

func TestJSCodeBSONToJSON(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("Converting BSON Javascript code to JSON", t, func() {
		Convey("should produce a json.Javascript", func() {
			Convey("without scope if the scope for the BSON Javascript code is nil", func() {
				_jObj, err := ConvertBSONValueToJSON(bson.JavaScript{"function() { return null; }", nil})
				So(err, ShouldBeNil)
				jObj, ok := _jObj.(json.JavaScript)
				So(ok, ShouldBeTrue)

				So(jObj, ShouldResemble, json.JavaScript{"function() { return null; }", nil})
			})

			Convey("with scope if the scope for the BSON Javascript code is non-nil", func() {
				_jObj, err := ConvertBSONValueToJSON(bson.JavaScript{"function() { return x; }", bson.M{"x": 2}})
				So(err, ShouldBeNil)
				jObj, ok := _jObj.(json.JavaScript)
				So(ok, ShouldBeTrue)
				So(jObj.Scope.(bson.M)["x"], ShouldEqual, 2)
				So(jObj.Code, ShouldEqual, "function() { return x; }")
			})
		})
	})
}
開發者ID:devsaurin,項目名稱:mongo-tools,代碼行數:25,代碼來源:converter_test.go

示例2: TestGetUpsertValue

func TestGetUpsertValue(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("Given a field and a BSON document, on calling getUpsertValue", t, func() {
		Convey("the value of the key should be correct for unnested "+
			"documents", func() {
			bsonDocument := bson.M{"a": 3}
			So(getUpsertValue("a", bsonDocument), ShouldEqual, 3)
		})
		Convey("the value of the key should be correct for nested "+
			"document fields", func() {
			bsonDocument := bson.M{"a": bson.M{"b": 4}}
			So(getUpsertValue("a.b", bsonDocument), ShouldEqual, 4)
		})
		Convey("the value of the key should be nil for unnested document "+
			"fields that do not exist", func() {
			bsonDocument := bson.M{"a": 4}
			So(getUpsertValue("c", bsonDocument), ShouldBeNil)
		})
		Convey("the value of the key should be nil for nested document "+
			"fields that do not exist", func() {
			bsonDocument := bson.M{"a": bson.M{"b": 4}}
			So(getUpsertValue("a.c", bsonDocument), ShouldBeNil)
		})
		Convey("the value of the key should be nil for nil document"+
			"values", func() {
			So(getUpsertValue("a", bson.M{"a": nil}), ShouldBeNil)
		})
	})
}
開發者ID:eshujiushiwo,項目名稱:mongo-tools,代碼行數:30,代碼來源:common_test.go

示例3: TestCreateIntentsForDB

func TestCreateIntentsForDB(t *testing.T) {
	// This tests creates intents based on the test file tree:
	//   db1
	//   db1/baddir
	//   db1/baddir/out.bson
	//   db1/c1.bson
	//   db1/c1.metadata.json
	//   db1/c2.bson
	//   db1/c3.bson
	//   db1/c3.metadata.json

	var mr *MongoRestore
	var buff bytes.Buffer

	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("With a test MongoRestore", t, func() {
		mr = newMongoRestore()
		log.SetWriter(&buff)

		Convey("running CreateIntentsForDB should succeed", func() {
			ddl, err := newActualPath("testdata/testdirs/db1")
			So(err, ShouldBeNil)
			err = mr.CreateIntentsForDB("myDB", ddl)
			So(err, ShouldBeNil)
			mr.manager.Finalize(intents.Legacy)

			Convey("and reading the intents should show alphabetical order", func() {
				i0 := mr.manager.Pop()
				So(i0.C, ShouldEqual, "c1")
				i1 := mr.manager.Pop()
				So(i1.C, ShouldEqual, "c2")
				i2 := mr.manager.Pop()
				So(i2.C, ShouldEqual, "c3")
				i3 := mr.manager.Pop()
				So(i3, ShouldBeNil)

				Convey("and all intents should have the supplied db name", func() {
					So(i0.DB, ShouldEqual, "myDB")
					So(i1.DB, ShouldEqual, "myDB")
					So(i2.DB, ShouldEqual, "myDB")
				})

				Convey("with all the proper metadata + bson merges", func() {
					So(i0.Location, ShouldNotEqual, "")
					So(i0.MetadataLocation, ShouldNotEqual, "")
					So(i1.Location, ShouldNotEqual, "")
					So(i1.MetadataLocation, ShouldEqual, "") //no metadata for this file
					So(i2.Location, ShouldNotEqual, "")
					So(i2.MetadataLocation, ShouldNotEqual, "")

					Convey("and skipped files all present in the logs", func() {
						logs := buff.String()
						So(strings.Contains(logs, "baddir"), ShouldEqual, true)
					})
				})
			})
		})
	})
}
開發者ID:Machyne,項目名稱:mongo,代碼行數:60,代碼來源:filepath_test.go

示例4: TestKerberos

func TestKerberos(t *testing.T) {
	testutil.VerifyTestType(t, testutil.KerberosTestType)

	Convey("Should be able to run mongoexport with Kerberos auth", t, func() {
		opts, err := testutil.GetKerberosOptions()

		So(err, ShouldBeNil)

		sessionProvider, err := db.NewSessionProvider(*opts)
		So(err, ShouldBeNil)

		export := MongoExport{
			ToolOptions:     *opts,
			OutputOpts:      &OutputFormatOptions{},
			InputOpts:       &InputOptions{},
			SessionProvider: sessionProvider,
		}

		var out bytes.Buffer
		num, err := export.exportInternal(&out)

		So(err, ShouldBeNil)
		So(num, ShouldEqual, 1)
		outputLines := strings.Split(strings.TrimSpace(out.String()), "\n")
		So(len(outputLines), ShouldEqual, 1)
		So(outputLines[0], ShouldEqual,
			"{\"_id\":{\"$oid\":\"528fb35afb3a8030e2f643c3\"},"+
				"\"authenticated\":\"yeah\",\"kerberos\":true}")
	})
}
開發者ID:eshujiushiwo,項目名稱:mongo-tools,代碼行數:30,代碼來源:kerberos_test.go

示例5: TestMongoDumpValidateOptions

func TestMongoDumpValidateOptions(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("With a MongoDump instance", t, func() {
		md := simpleMongoDumpInstance()

		Convey("we cannot dump a collection when a database specified", func() {
			md.ToolOptions.Namespace.Collection = "some_collection"
			md.ToolOptions.Namespace.DB = ""

			err := md.Init()
			So(err, ShouldNotBeNil)
			So(err.Error(), ShouldContainSubstring, "cannot dump a collection without a specified database")
		})

		Convey("we have to specify a collection name if using a query", func() {
			md.ToolOptions.Namespace.Collection = ""
			md.OutputOptions.Out = ""
			md.InputOptions.Query = "{_id:\"\"}"

			err := md.Init()
			So(err, ShouldNotBeNil)
			So(err.Error(), ShouldContainSubstring, "cannot dump using a query without a specified collection")
		})

	})
}
開發者ID:Machyne,項目名稱:mongo,代碼行數:27,代碼來源:mongodump_test.go

示例6: TestJSONArray

func TestJSONArray(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("With a JSON export output in array mode", t, func() {
		out := &bytes.Buffer{}
		Convey("exporting a bunch of documents should produce valid json", func() {
			jsonExporter := NewJSONExportOutput(true, false, out)
			err := jsonExporter.WriteHeader()
			So(err, ShouldBeNil)

			// Export a few docs of various types

			testObjs := []interface{}{bson.NewObjectId(), "asd", 12345, 3.14159, bson.M{"A": 1}}
			for _, obj := range testObjs {
				err = jsonExporter.ExportDocument(bson.M{"_id": obj})
				So(err, ShouldBeNil)
			}

			err = jsonExporter.WriteFooter()
			So(err, ShouldBeNil)
			// Unmarshal the whole thing, it should be valid json
			fromJSON := []map[string]interface{}{}
			err = json.Unmarshal(out.Bytes(), &fromJSON)
			So(err, ShouldBeNil)
			So(len(fromJSON), ShouldEqual, len(testObjs))

		})

		Reset(func() {
			out.Reset()
		})

	})
}
開發者ID:eshujiushiwo,項目名稱:mongo-tools,代碼行數:34,代碼來源:json_test.go

示例7: TestWriteJSON

func TestWriteJSON(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("With a JSON export output", t, func() {
		out := &bytes.Buffer{}

		Convey("Special types should serialize as extended JSON", func() {

			Convey("ObjectId should have an extended JSON format", func() {
				jsonExporter := NewJSONExportOutput(false, false, out)
				objId := bson.NewObjectId()
				err := jsonExporter.WriteHeader()
				So(err, ShouldBeNil)
				err = jsonExporter.ExportDocument(bson.M{"_id": objId})
				So(err, ShouldBeNil)
				err = jsonExporter.WriteFooter()
				So(err, ShouldBeNil)
				So(out.String(), ShouldEqual, `{"_id":{"$oid":"`+objId.Hex()+`"}}`+"\n")
			})

			Reset(func() {
				out.Reset()
			})
		})

	})
}
開發者ID:eshujiushiwo,項目名稱:mongo-tools,代碼行數:27,代碼來源:json_test.go

示例8: TestRemoveBlankFields

func TestRemoveBlankFields(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("Given an unordered BSON document", t, func() {
		Convey("the same document should be returned if there are no blanks", func() {
			bsonDocument := bson.D{bson.DocElem{"a", 3}, bson.DocElem{"b", "hello"}}
			So(removeBlankFields(bsonDocument), ShouldResemble, bsonDocument)
		})
		Convey("a new document without blanks should be returned if there are "+
			" blanks", func() {
			bsonDocument := bson.D{
				bson.DocElem{"a", 0},
				bson.DocElem{"b", ""},
				bson.DocElem{"c", ""},
				bson.DocElem{"d", &bson.D{
					bson.DocElem{"a", ""},
					bson.DocElem{"b", ""},
				}},
				bson.DocElem{"e", &bson.D{
					bson.DocElem{"a", ""},
					bson.DocElem{"b", 1},
				}},
			}
			expectedDocument := bson.D{
				bson.DocElem{"a", 0},
				bson.DocElem{"e", bson.D{
					bson.DocElem{"b", 1},
				}},
			}
			So(removeBlankFields(bsonDocument), ShouldResemble, expectedDocument)
		})
	})
}
開發者ID:eshujiushiwo,項目名稱:mongo-tools,代碼行數:33,代碼來源:common_test.go

示例9: TestFilterIngestError

func TestFilterIngestError(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("Given a boolean 'stopOnError' and an error...", t, func() {

		Convey("an error should be returned if stopOnError is true the err is not nil", func() {
			So(filterIngestError(true, fmt.Errorf("")), ShouldNotBeNil)
		})

		Convey("errLostConnection should be returned if stopOnError is true the err is io.EOF", func() {
			So(filterIngestError(true, io.EOF), ShouldEqual, db.ErrLostConnection)
		})

		Convey("no error should be returned if stopOnError is false the err is not nil", func() {
			So(filterIngestError(false, fmt.Errorf("")), ShouldBeNil)
		})

		Convey("no error should be returned if stopOnError is false the err is nil", func() {
			So(filterIngestError(false, nil), ShouldBeNil)
		})

		Convey("no error should be returned if stopOnError is true the err is nil", func() {
			So(filterIngestError(true, nil), ShouldBeNil)
		})
	})
}
開發者ID:eshujiushiwo,項目名稱:mongo-tools,代碼行數:26,代碼來源:common_test.go

示例10: TestGetSourceReader

func TestGetSourceReader(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)
	Convey("Given a mongoimport instance, on calling getSourceReader", t,
		func() {
			Convey("an error should be thrown if the given file referenced by "+
				"the reader does not exist", func() {
				imp, err := NewMongoImport()
				So(err, ShouldBeNil)
				imp.InputOptions.File = "/path/to/input/file/dot/input.txt"
				imp.InputOptions.Type = CSV
				imp.ToolOptions.Namespace.Collection = ""
				_, _, err = imp.getSourceReader()
				So(err, ShouldNotBeNil)
			})

			Convey("no error should be thrown if the file exists", func() {
				imp, err := NewMongoImport()
				So(err, ShouldBeNil)
				imp.InputOptions.File = "testdata/test_array.json"
				imp.InputOptions.Type = JSON
				_, _, err = imp.getSourceReader()
				So(err, ShouldBeNil)
			})

			Convey("no error should be thrown if stdin is used", func() {
				imp, err := NewMongoImport()
				So(err, ShouldBeNil)
				imp.InputOptions.File = ""
				_, _, err = imp.getSourceReader()
				So(err, ShouldBeNil)
			})
		})
}
開發者ID:devsaurin,項目名稱:mongo-tools,代碼行數:33,代碼來源:mongoimport_test.go

示例11: TestFailpointParsing

func TestFailpointParsing(t *testing.T) {
	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("With test args", t, func() {
		args := "foo=bar,baz,biz=,=a"
		ParseFailpoints(args)

		So(Enabled("foo"), ShouldBeTrue)
		So(Enabled("baz"), ShouldBeTrue)
		So(Enabled("biz"), ShouldBeTrue)
		So(Enabled(""), ShouldBeTrue)
		So(Enabled("bar"), ShouldBeFalse)

		var val string
		var ok bool
		val, ok = Get("foo")
		So(val, ShouldEqual, "bar")
		So(ok, ShouldBeTrue)
		val, ok = Get("baz")
		So(val, ShouldEqual, "")
		So(ok, ShouldBeTrue)
		val, ok = Get("biz")
		So(val, ShouldEqual, "")
		So(ok, ShouldBeTrue)
		val, ok = Get("")
		So(val, ShouldEqual, "a")
		So(ok, ShouldBeTrue)
		val, ok = Get("bar")
		So(ok, ShouldBeFalse)
	})
}
開發者ID:Machyne,項目名稱:mongo,代碼行數:31,代碼來源:failpoint_test.go

示例12: TestBufferPoolRecycling

func TestBufferPoolRecycling(t *testing.T) {

	testutil.VerifyTestType(t, "unit")

	Convey("With a BufferPool of size 1", t, func() {
		bp := NewBufferPool(1)
		So(bp, ShouldNotBeNil)

		Convey("get a buffer from the pool and then return it", func() {
			a := bp.Get()
			So(len(a), ShouldEqual, 1)
			a[0] = 'a'
			bp.Put(a)

			Convey("so now getting a buffer should recycle the previous buffer", func() {
				newA := bp.Get()
				So(newA[0], ShouldEqual, 'a')

				newA[0] = 'X'
				So(a[0], ShouldEqual, 'X') //assure both point to the same thing

				Convey("but getting a second new buffer should be clean", func() {
					newB := bp.Get()
					So(newB[0], ShouldNotEqual, 'a')
					So(newB[0], ShouldNotEqual, 'X')
				})
			})
		})
	})
}
開發者ID:shelman,項目名稱:mongo-tools-proto,代碼行數:30,代碼來源:buffer_pool_test.go

示例13: TestDBCounterCollectionSorting

func TestDBCounterCollectionSorting(t *testing.T) {

	testutil.VerifyTestType(t, testutil.UnitTestType)

	Convey("With a dbCounter and an unordered collection of intents", t, func() {
		dbc := &dbCounter{
			collections: []*Intent{
				&Intent{Size: 100},
				&Intent{Size: 1000},
				&Intent{Size: 1},
				&Intent{Size: 10},
			},
		}

		Convey("popping the sorted intents should return in decreasing BSONSize", func() {
			dbc.SortCollectionsBySize()
			So(dbc.PopIntent().Size, ShouldEqual, 1000)
			So(dbc.PopIntent().Size, ShouldEqual, 100)
			So(dbc.PopIntent().Size, ShouldEqual, 10)
			So(dbc.PopIntent().Size, ShouldEqual, 1)
			So(dbc.PopIntent(), ShouldBeNil)
			So(dbc.PopIntent(), ShouldBeNil)
		})
	})
}
開發者ID:devsaurin,項目名稱:mongo-tools,代碼行數:25,代碼來源:intent_prioritizer_test.go

示例14: TestNumberConverter

func TestNumberConverter(t *testing.T) {

	testutil.VerifyTestType(t, "unit")

	Convey("With a number converter for float32", t, func() {
		floatConverter := newNumberConverter(reflect.TypeOf(float32(0)))

		Convey("numeric values should be convertable", func() {
			out, err := floatConverter(21)
			So(err, ShouldEqual, nil)
			So(out, ShouldEqual, 21.0)
			out, err = floatConverter(uint64(21))
			So(err, ShouldEqual, nil)
			So(out, ShouldEqual, 21.0)
			out, err = floatConverter(float64(27.52))
			So(err, ShouldEqual, nil)
			So(out, ShouldEqual, 27.52)
		})

		Convey("non-numeric values should fail", func() {
			_, err := floatConverter("I AM A STRING")
			So(err, ShouldNotBeNil)
			_, err = floatConverter(struct{ int }{12})
			So(err, ShouldNotBeNil)
			_, err = floatConverter(nil)
			So(err, ShouldNotBeNil)
		})
	})
}
開發者ID:devsaurin,項目名稱:mongo-tools,代碼行數:29,代碼來源:math_test.go

示例15: TestKerberos

func TestKerberos(t *testing.T) {
	testutil.VerifyTestType(t, testutil.KerberosTestType)

	Convey("Should be able to run mongoexport with Kerberos auth", t, func() {
		opts, err := testutil.GetKerberosOptions()

		So(err, ShouldBeNil)

		sessionProvider, err := db.NewSessionProvider(*opts)
		So(err, ShouldBeNil)

		export := MongoExport{
			ToolOptions:     *opts,
			OutputOpts:      &OutputFormatOptions{},
			InputOpts:       &InputOptions{},
			SessionProvider: sessionProvider,
		}

		var out bytes.Buffer
		num, err := export.exportInternal(&out)

		So(err, ShouldBeNil)
		So(num, ShouldEqual, 1)
		outputLines := strings.Split(strings.TrimSpace(out.String()), "\n")
		So(len(outputLines), ShouldEqual, 1)
		outMap := map[string]interface{}{}
		So(json.Unmarshal([]byte(outputLines[0]), &outMap), ShouldBeNil)
		So(outMap["kerberos"], ShouldEqual, true)
		So(outMap["authenticated"], ShouldEqual, "yeah")
		So(outMap["_id"].(map[string]interface{})["$oid"], ShouldEqual, "528fb35afb3a8030e2f643c3")
	})
}
開發者ID:devsaurin,項目名稱:mongo-tools,代碼行數:32,代碼來源:kerberos_test.go


注:本文中的github.com/mongodb/mongo-tools/common/testutil.VerifyTestType函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。