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


Golang ensure.DeepEqual函數代碼示例

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


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

示例1: TestAverage

func TestAverage(t *testing.T) {
	t.Parallel()
	ensure.DeepEqual(t, stats.Average([]float64{}), 0.0)
	ensure.DeepEqual(t, stats.Average([]float64{1}), 1.0)
	ensure.DeepEqual(t, stats.Average([]float64{1, 2}), 1.5)
	ensure.DeepEqual(t, stats.Average([]float64{1, 2, 3}), 2.0)
}
開發者ID:facebookgo,項目名稱:stats,代碼行數:7,代碼來源:aggregation_test.go

示例2: TestMergeOperator

func TestMergeOperator(t *testing.T) {
	var (
		givenKey    = []byte("hello")
		givenVal1   = []byte("foo")
		givenVal2   = []byte("bar")
		givenMerged = []byte("foobar")
	)
	merger := &mockMergeOperator{
		fullMerge: func(key, existingValue []byte, operands [][]byte) ([]byte, bool) {
			ensure.DeepEqual(&fatalAsError{t}, key, givenKey)
			ensure.DeepEqual(&fatalAsError{t}, existingValue, givenVal1)
			ensure.DeepEqual(&fatalAsError{t}, operands, [][]byte{givenVal2})
			return givenMerged, true
		},
	}
	db := newTestDB(t, "TestMergeOperator", func(opts *Options) {
		opts.SetMergeOperator(merger)
	})
	defer db.Close()

	wo := NewDefaultWriteOptions()
	ensure.Nil(t, db.Put(wo, givenKey, givenVal1))
	ensure.Nil(t, db.Merge(wo, givenKey, givenVal2))

	// trigger a compaction to ensure that a merge is performed
	db.CompactRange(Range{nil, nil})

	ro := NewDefaultReadOptions()
	v1, err := db.Get(ro, givenKey)
	defer v1.Free()
	ensure.Nil(t, err)
	ensure.DeepEqual(t, v1.Data(), givenMerged)
}
開發者ID:arbortech,項目名稱:gorocksdb,代碼行數:33,代碼來源:merge_operator_test.go

示例3: TestReadTriggerParams

func TestReadTriggerParams(t *testing.T) {
	t.Parallel()

	h := newHarness(t)
	defer h.Stop()

	h.env.In = ioutil.NopCloser(strings.NewReader("\n"))
	_, err := readTriggerName(h.env)
	ensure.Err(t, err, regexp.MustCompile("Class name cannot be empty"))

	h.env.In = ioutil.NopCloser(strings.NewReader("foo\n"))
	_, err = readTriggerName(h.env)
	ensure.Err(t, err, regexp.MustCompile("Trigger name cannot be empty"))

	h.env.In = ioutil.NopCloser(strings.NewReader("foo\nbeforeSave"))
	hook, err := readTriggerName(h.env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, *hook, triggerHook{ClassName: "foo", TriggerName: "beforeSave"})

	h.env.In = ioutil.NopCloser(strings.NewReader("foo\nbeforeSave\napi.example.com/foo/beforeSave\n"))
	hook, err = readTriggerParams(h.env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, *hook, triggerHook{
		ClassName:   "foo",
		TriggerName: "beforeSave",
		URL:         "https://api.example.com/foo/beforeSave",
	})
}
開發者ID:huamichaelchen,項目名稱:parse-cli,代碼行數:28,代碼來源:triggers_cmd_test.go

示例4: TestConfigureAcessToken

func TestConfigureAcessToken(t *testing.T) {
	t.Parallel()

	h, _ := newAppHarness(t)
	defer h.Stop()

	c := configureCmd{login: login{tokenReader: strings.NewReader("")}}
	h.env.In = ioutil.NopCloser(strings.NewReader("n\ntoken\n"))
	ensure.Nil(t, c.accessToken(h.env))
	ensure.DeepEqual(t,
		h.Out.String(),
		`Please enter an access token if you already generated it.
If you do not have an access token or would like to generate a new one,
please type: "y" to open the browser or "n" to continue: Access Token: Successfully stored credentials.
`,
	)
	h.env.In = ioutil.NopCloser(strings.NewReader("n\nemail\ninvalid\n"))
	ensure.Err(t, c.accessToken(h.env), regexp.MustCompile("Please try again"))
	ensure.DeepEqual(t,
		h.Err.String(),
		`Sorry, the access token you provided is not valid.
Please follow instructions at https://www.parse.com/account_keys to generate a new access token.
`,
	)
}
開發者ID:google2013,項目名稱:parse-cli,代碼行數:25,代碼來源:configure_cmd_test.go

示例5: TestWriteBatch

func TestWriteBatch(t *testing.T) {
	db := newTestDB(t, "TestWriteBatch", nil)
	defer db.Close()

	var (
		givenKey1 = []byte("key1")
		givenVal1 = []byte("val1")
		givenKey2 = []byte("key2")
	)
	wo := NewDefaultWriteOptions()
	ensure.Nil(t, db.Put(wo, givenKey2, []byte("foo")))

	// create and fill the write batch
	wb := NewWriteBatch()
	defer wb.Destroy()
	wb.Put(givenKey1, givenVal1)
	wb.Delete(givenKey2)
	ensure.DeepEqual(t, wb.Count(), 2)

	// perform the batch
	ensure.Nil(t, db.Write(wo, wb))

	// check changes
	ro := NewDefaultReadOptions()
	v1, err := db.Get(ro, givenKey1)
	defer v1.Free()
	ensure.Nil(t, err)
	ensure.DeepEqual(t, v1.Data(), givenVal1)

	v2, err := db.Get(ro, givenKey2)
	defer v2.Free()
	ensure.Nil(t, err)
	ensure.True(t, v2.Data() == nil)
}
開發者ID:arbortech,項目名稱:gorocksdb,代碼行數:34,代碼來源:write_batch_test.go

示例6: TestUploadSourceFilesChanged

func TestUploadSourceFilesChanged(t *testing.T) {
	t.Parallel()
	h := createParseProject(t)
	defer h.Stop()

	u := &uploader{
		DirName:  "cloud",
		Suffixes: map[string]struct{}{".js": {}},
		EndPoint: "uploads",
		Env:      h.env,
		PrevChecksums: map[string]string{
			"main.js": "d41d8cd98f00b204e9800998ecf8427e",
		},
		PrevVersions: map[string]string{
			"main.js": "f1",
		},
	}

	ht := transportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/uploads")
		return &http.Response{
			StatusCode: http.StatusOK,
			Body:       ioutil.NopCloser(strings.NewReader(`{"version": "f2"}`)),
		}, nil
	})

	h.env.ParseAPIClient = &ParseAPIClient{apiClient: &parse.Client{Transport: ht}}

	var d deployCmd
	checksums, versions, err := d.uploadSourceFiles(u)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, checksums, map[string]string{"main.js": "4ece160cc8e5e828ee718e7367cf5d37"})
	ensure.DeepEqual(t, versions, map[string]string{"main.js": "f2"})
}
開發者ID:Georotzen,項目名稱:parse-cli,代碼行數:34,代碼來源:deploy_cmd_test.go

示例7: TestLogin

func TestLogin(t *testing.T) {
	t.Parallel()

	h, _ := newAppHarness(t)
	defer h.Stop()

	l := &loginCmd{tokenReader: strings.NewReader("")}

	h.env.In = ioutil.NopCloser(strings.NewReader("n\nemail\ntoken\n"))
	ensure.Nil(t, l.run(h.env))
	ensure.DeepEqual(t,
		h.Out.String(),
		`Please enter the email id you used to register with Parse
and an account key if you already generated it.
If you do not have an account key or would like to generate a new one,
please type: "y" to open the browser or "n" to continue: Email: Account Key: Successfully stored credentials.
`)

	h.env.In = ioutil.NopCloser(strings.NewReader("n\nemail\ninvalid\n"))
	ensure.Err(t, l.run(h.env), regexp.MustCompile("Please try again"))
	ensure.DeepEqual(t,
		h.Err.String(),
		`Sorry, we do not have a user with this email and account key.
Please follow instructions at https://www.parse.com/account/keys to generate a new account key.
`)
}
開發者ID:huamichaelchen,項目名稱:parse-cli,代碼行數:26,代碼來源:login_cmd_test.go

示例8: TestEncodeUint

func TestEncodeUint(t *testing.T) {
	var buf bytes.Buffer

	// Uint8
	var ui8 uint8
	ui8 = math.MaxUint8
	ensure.Nil(t, encode(&buf, reflect.ValueOf(ui8)))
	ensure.DeepEqual(t, fmt.Sprintf("%d\r\n", ui8), buf.String())
	buf.Reset()

	// Uint16
	var ui16 uint16
	ui16 = math.MaxUint16
	ensure.Nil(t, encode(&buf, reflect.ValueOf(ui16)))
	ensure.DeepEqual(t, fmt.Sprintf("%d\r\n", ui16), buf.String())
	buf.Reset()

	// Uint32
	var ui32 uint32
	ui32 = math.MaxUint32
	ensure.Nil(t, encode(&buf, reflect.ValueOf(ui32)))
	ensure.DeepEqual(t, fmt.Sprintf("%d\r\n", ui32), buf.String())
	buf.Reset()

	// Uint64
	var ui64 uint64
	ui64 = math.MaxUint64
	ensure.Nil(t, encode(&buf, reflect.ValueOf(ui64)))
	ensure.DeepEqual(t, fmt.Sprintf("%v\r\n", ui64), buf.String())
	buf.Reset()
}
開發者ID:heltonmarx,項目名稱:goami,代碼行數:31,代碼來源:encode_test.go

示例9: TestShouldCreateNewApp

func TestShouldCreateNewApp(t *testing.T) {
	t.Parallel()
	h := parsecli.NewHarness(t)
	defer h.Stop()

	n := &newCmd{}

	h.Env.In = ioutil.NopCloser(strings.NewReader("new"))
	decision, err := n.promptCreateNewApp(h.Env, false)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, decision, "new")

	h.Env.In = ioutil.NopCloser(strings.NewReader("existing"))
	decision, err = n.promptCreateNewApp(h.Env, false)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, decision, "existing")

	h.Env.In = ioutil.NopCloser(strings.NewReader("other"))
	_, err = n.promptCreateNewApp(h.Env, false)
	ensure.Err(t, err, regexp.MustCompile("are the only valid options"))

	decision, err = n.promptCreateNewApp(h.Env, true)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, decision, "existing")

	n.createNewApp = true
	decision, err = n.promptCreateNewApp(h.Env, true)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, decision, "new")
}
開發者ID:z7z8th,項目名稱:parse-cli,代碼行數:30,代碼來源:new_test.go

示例10: TestGetHostFromURL

func TestGetHostFromURL(t *testing.T) {
	urlStr := "https://api.parse.com/1/"
	host, err := getHostFromURL(urlStr, "")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, host, "api.parse.com")

	urlStr = "https://api.parse.com/1/"
	host, err = getHostFromURL(urlStr, "[email protected]")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, host, "api.parse.com#[email protected]")

	urlStr = "https://api.example.com:8080/1/"
	host, err = getHostFromURL(urlStr, "")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, host, "api.example.com")

	urlStr = "https://api.example.com:8080/1/"
	host, err = getHostFromURL(urlStr, "[email protected]")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, host, "api.example.com#[email protected]")

	urlStr = "api.example.com:8080:90"
	host, err = getHostFromURL(urlStr, "")
	ensure.Err(t, err, regexp.MustCompile("not a valid url"))
}
開發者ID:Georotzen,項目名稱:parse-cli,代碼行數:25,代碼來源:utils_test.go

示例11: TestBatchDo

func TestBatchDo(t *testing.T) {
	const (
		method      = "GET"
		relativeURL = "/me"
		accessToken = "at"
		appID       = 42
	)
	given := []*Response{{Code: 42}}
	br := &Request{
		Method:      method,
		RelativeURL: relativeURL,
	}
	b := &Batch{
		AccessToken: accessToken,
		AppID:       appID,
		Request:     []*Request{br},
	}
	c := &fbapi.Client{
		Transport: fTransport(func(r *http.Request) (*http.Response, error) {
			ensure.Nil(t, r.ParseForm())
			ensure.DeepEqual(t, r.URL.String(), "https://graph.facebook.com/")
			ensure.DeepEqual(t, r.Method, "POST")
			ensure.DeepEqual(t, r.PostFormValue("access_token"), accessToken)
			ensure.DeepEqual(t, r.PostFormValue("batch_app_id"), fmt.Sprint(appID))
			return &http.Response{
				StatusCode: http.StatusOK,
				Body:       ioutil.NopCloser(jsonpipe.Encode(given)),
			}, nil
		}),
	}
	actual, err := BatchDo(c, b)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, actual, given)
}
開發者ID:jimneath,項目名稱:fbapi,代碼行數:34,代碼來源:fbbatch_test.go

示例12: CheckOpsReader

// Verify if the items being read are as expected.
func CheckOpsReader(t *testing.T, loader OpsReader) {
	expectedOpsRead := 0
	const startingTs = 1396456709420
	for op := loader.Next(); op != nil; op = loader.Next() {
		expectedOpsRead += 1
		ensure.NotNil(t, op)
		ensure.DeepEqual(t, loader.OpsRead(), expectedOpsRead)

		// check the "ts" field
		CheckTime(t, float64(startingTs+loader.OpsRead()), op.Timestamp)

		// check the insert doc
		// certain key exists
		for i := 1; i <= 5; i++ {
			logTypeKey := fmt.Sprintf("logType%d", i)
			logType, ok := GetElem(op.InsertDoc, logTypeKey)
			if i != expectedOpsRead {
				ensure.False(t, ok)
				ensure.Nil(t, logType)
			} else {
				ensure.True(t, ok)
				ensure.NotNil(t, logType)
			}
		}
		// check the value for the shared key
		message := fmt.Sprintf("m%d", expectedOpsRead)
		actualMessage, ok := GetElem(op.InsertDoc, "message")
		ensure.True(t, ok)
		ensure.DeepEqual(t, actualMessage.(string), message)
	}
	ensure.DeepEqual(t, expectedOpsRead, 5)
}
開發者ID:bradparks,項目名稱:flashback,代碼行數:33,代碼來源:ops_reader_test.go

示例13: TestPrepareInheriteFiles

func TestPrepareInheriteFiles(t *testing.T) {
	var n Net

	port1, err := freeport.Get()
	ensure.Nil(t, err)
	addr1 := fmt.Sprintf(":%d", port1)
	l1, err := net.Listen("tcp", addr1)
	ensure.Nil(t, err)

	port2, err := freeport.Get()
	ensure.Nil(t, err)
	addr2 := fmt.Sprintf(":%d", port2)
	l2, err := net.Listen("tcp", addr2)
	ensure.Nil(t, err)

	files, err := n.prepareInheriteFiles([]net.Listener{l1, l2})
	ensure.Nil(t, err)
	ensure.DeepEqual(t, len(files), 2)

	// assign both to prevent GC from kicking in the finalizer
	fds := []int{dup(t, int(files[0].Fd())), dup(t, int(files[0].Fd()))}
	n.fdStart = fds[0]
	os.Setenv(envCountKey, "2")
	// Close these after to ensure we get coalaced file descriptors.
	ensure.Nil(t, l1.Close())
	ensure.Nil(t, l2.Close())

	ensure.Nil(t, n.inherit())
	ensure.DeepEqual(t, len(n.inherited), 2)
}
開發者ID:absolute8511,項目名稱:grace,代碼行數:30,代碼來源:net_test.go

示例14: TestSecondUnixListenInherited

func TestSecondUnixListenInherited(t *testing.T) {
	var n Net
	tmpfile, err := ioutil.TempFile("", "TestSecondUnixListenInherited-")
	ensure.Nil(t, err)
	ensure.Nil(t, tmpfile.Close())
	ensure.Nil(t, os.Remove(tmpfile.Name()))
	defer os.Remove(tmpfile.Name())
	l1, err := net.Listen("unix", tmpfile.Name())
	ensure.Nil(t, err)
	file, err := l1.(*net.UnixListener).File()
	ensure.Nil(t, err)
	n.fdStart = dup(t, int(file.Fd()))
	ensure.Nil(t, file.Close())
	os.Setenv(envCountKey, "1")
	ensure.Nil(t, n.inherit())
	ensure.DeepEqual(t, len(n.inherited), 1)
	l2, err := n.Listen("unix", tmpfile.Name())
	ensure.Nil(t, err)
	ensure.DeepEqual(t, len(n.active), 1)
	ensure.DeepEqual(t, n.inherited[0], nil)
	_, err = n.Listen("unix", tmpfile.Name())
	ensure.Err(t, err, regexp.MustCompile("bind: address already in use$"))
	ensure.Nil(t, l1.Close())
	ensure.Nil(t, l2.Close())
}
開發者ID:absolute8511,項目名稱:grace,代碼行數:25,代碼來源:net_test.go

示例15: TestMakeNewRelease

func TestMakeNewRelease(t *testing.T) {
	t.Parallel()
	h := newHarness(t)
	defer h.Stop()

	var d deployCmd
	info := deployInfo{
		ReleaseName:  "v2",
		ParseVersion: "latest",
		Checksums: deployFileData{
			Cloud:  map[string]string{"main.js": "4ece160cc8e5e828ee718e7367cf5d37"},
			Public: map[string]string{"index.html": "9e2354a0ebac5852bc674026137c8612"},
		},
		Versions: deployFileData{
			Cloud:  map[string]string{"main.js": "f2"},
			Public: map[string]string{"index.html": "f2"},
		},
	}
	ht := transportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/deploy")
		return &http.Response{
			StatusCode: http.StatusOK,
			Body:       ioutil.NopCloser(strings.NewReader(jsonStr(t, &info))),
		}, nil
	})
	h.env.ParseAPIClient = &ParseAPIClient{apiClient: &parse.Client{Transport: ht}}
	res, err := d.makeNewRelease(&deployInfo{}, h.env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, info, res)
}
開發者ID:Georotzen,項目名稱:parse-cli,代碼行數:30,代碼來源:deploy_cmd_test.go


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