• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang assert.Equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/getlantern/testify/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestNestedField

func TestNestedField(t *testing.T) {
	d := makeData()
	orig := d.B

	p := Parse("B")
	err := p.Set(d, &B{
		S: "10",
		I: 10,
	})

	assert.NoError(t, err, "Setting struct should succeed")
	assert.Equal(t, "10", d.B.S, "string field should reflect value from new struct")
	assert.Equal(t, 10, d.B.I, "int field should reflect value from new struct")
	assert.NotEqual(t, d.B, orig, "struct should change")

	gotten, err := Parse("B/S").Get(d)
	assert.NoError(t, err, "Getting nested string should succeed")
	assert.Equal(t, "10", gotten, "Getting nested string should have gotten right value")

	err = p.Clear(d)
	assert.NoError(t, err, "Clearing struct should succeed")
	assert.Nil(t, d.B, "struct should be nil after clearing")

	zv, err := p.ZeroValue(d)
	assert.NoError(t, err, "Getting zero value of struct should succeed")
	assert.Equal(t, &B{}, zv, "Zero value of struct should match expected")
}
开发者ID:Christeefym,项目名称:lantern,代码行数:27,代码来源:pathreflect_test.go


示例2: TestNestedMapEntry

func TestNestedMapEntry(t *testing.T) {
	d := makeData()
	orig := d.MapB["3"]

	p := Parse("MapB/3")
	err := p.Set(d, &B{
		S: "10",
		I: 10,
	})

	assert.NoError(t, err, "Setting struct should succeed")
	assert.Equal(t, "10", d.MapB["3"].S, "string field should reflect value from new struct")
	assert.Equal(t, 10, d.MapB["3"].I, "int field should reflect value from new struct")
	assert.NotEqual(t, d.B, orig, "struct should change")

	gotten, err := Parse("MapB/3/S").Get(d)
	assert.NoError(t, err, "Getting nested string should succeed")
	assert.Equal(t, "10", gotten, "Getting nested string should have gotten right value")

	err = p.Clear(d)
	assert.NoError(t, err, "Clearing struct should succeed")
	_, found := d.MapB["3"]
	assert.False(t, found, "struct should be gone from map after clearing")

	zv, err := p.ZeroValue(d)
	assert.NoError(t, err, "Getting zero value of struct should succeed")
	assert.Equal(t, &B{}, zv, "Zero value of struct should match expected")
}
开发者ID:Christeefym,项目名称:lantern,代码行数:28,代码来源:pathreflect_test.go


示例3: TestConcurrent

func TestConcurrent(t *testing.T) {
	v := NewValue()

	var sets int32 = 0

	go func() {
		var wg sync.WaitGroup
		wg.Add(1)
		// Do some concurrent setting to make sure that it works
		for i := 0; i < concurrency; i++ {
			go func() {
				// Wait for waitGroup so that all goroutines run at basically the same
				// time.
				wg.Wait()
				v.Set("hi")
				atomic.AddInt32(&sets, 1)
			}()
		}
		wg.Done()
	}()

	time.Sleep(50 * time.Millisecond)
	r, ok := v.Get(20 * time.Millisecond)
	assert.True(t, ok, "Get should have succeed")
	assert.Equal(t, "hi", r, "Wrong result")
	assert.Equal(t, concurrency, atomic.LoadInt32(&sets), "Wrong number of successful Sets")
}
开发者ID:2722,项目名称:lantern,代码行数:27,代码来源:eventual_test.go


示例4: doTestConn

func doTestConn(t *testing.T, conn net.Conn) {
	defer func() {
		if err := conn.Close(); err != nil {
			log.Debugf("Unable to close connection: %v", err)
		}
	}()

	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		n, err := conn.Write(msg)
		assert.NoError(t, err, "Writing should have succeeded")
		assert.Equal(t, len(msg), n, "Should have written full message")
		wg.Done()
	}()
	go func() {
		b := make([]byte, len(msg))
		n, err := io.ReadFull(conn, b)
		assert.NoError(t, err, "Read should have succeeded")
		assert.Equal(t, len(msg), n, "Should have read full message")
		assert.Equal(t, msg, b[:n], "Read should have matched written")
		wg.Done()
	}()

	wg.Wait()
}
开发者ID:ComeOn-Wuhan,项目名称:lantern,代码行数:26,代码来源:balancer_test.go


示例5: TestLoggly

func TestLoggly(t *testing.T) {
	var buf bytes.Buffer
	var result map[string]interface{}
	loggly := loggly.New("token not required")
	loggly.Writer = &buf
	lw := logglyErrorWriter{client: loggly}
	golog.SetOutputs(lw, nil)
	log := golog.LoggerFor("test")

	log.Error("")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+)"), result["message"])
	}

	buf.Reset()
	log.Error("short message")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) short message"), result["message"])
	}

	buf.Reset()
	log.Error("message with: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Regexp(t, "logging_test.go:([0-9]+) message with: reason", result["message"])
	}

	buf.Reset()
	log.Error("deep reason: message with: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Equal(t, "message with: reason", result["message"], "message should be last 2 chunks")
	}

	buf.Reset()
	log.Error("deep reason: an url https://a.com in message: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "an url https://a.com in message: reason", result["message"], "should not truncate url")
	}

	buf.Reset()
	log.Error("deep reason: an url 127.0.0.1:8787 in message: reason")
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])
		assert.Equal(t, "an url 127.0.0.1:8787 in message: reason", result["message"], "should not truncate url")
	}

	buf.Reset()
	longPrefix := "message with: really l"
	longMsg := longPrefix + strings.Repeat("o", 100) + "ng reason"
	log.Error(longMsg)
	if assert.NoError(t, json.Unmarshal(buf.Bytes(), &result), "Unmarshal error") {
		assert.Equal(t, "ERROR test", result["locationInfo"])

		assert.Regexp(t, regexp.MustCompile("logging_test.go:([0-9]+) "+longPrefix+"(o+)"), result["message"])
		assert.Equal(t, 100, len(result["message"].(string)))
	}
}
开发者ID:journeyqiao,项目名称:http-proxy,代码行数:60,代码来源:logging_test.go


示例6: TestConfigureAndPAC

func TestConfigureAndPAC(t *testing.T) {
	expectedDeltaA := &Delta{
		Additions: []string{"A", "B", "D"},
	}
	expectedDeltaB := &Delta{
		Additions: []string{"E"},
		Deletions: []string{"B", "D"},
	}

	delta := Configure(&Config{
		Cloud: []string{"A", "B", "C"},
		Delta: &Delta{
			Additions: []string{"D"},
			Deletions: []string{"C"},
		},
	})
	assert.Equal(t, expectedDeltaA, delta)

	delta = Configure(&Config{
		Cloud: []string{"A", "B", "C"},
		Delta: &Delta{
			Additions: []string{"E"},
			Deletions: []string{"B", "C"},
		},
	})
	assert.Equal(t, expectedDeltaB, delta)
}
开发者ID:2722,项目名称:lantern,代码行数:27,代码来源:proxiedsites_test.go


示例7: TestLines

func TestLines(t *testing.T) {
	buf := bytes.NewBuffer(nil)
	i := int32(0)
	w := LinePrepender(buf, func(w io.Writer) (int, error) {
		j := atomic.AddInt32(&i, 1)
		return fmt.Fprintf(w, "%d ", j)
	})

	n, err := fmt.Fprint(w, "A")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 1, n, "Wrong bytes written for A")
	}
	n, err = fmt.Fprintln(w, "")
	if assert.NoError(t, err, "Error writing newline after A") {
		assert.Equal(t, 1, n, "Wrong bytes written for newline after A")
	}
	n, err = fmt.Fprintf(w, "B\nC")
	if assert.NoError(t, err, "Error writing BC") {
		assert.Equal(t, 3, n, "Wrong bytes written for BC")
	}
	n, err = fmt.Fprintln(w, "\nD")
	if assert.NoError(t, err, "Error writing D") {
		assert.Equal(t, 3, n, "Wrong bytes written for D")
	}

	assert.Equal(t, expected, string(buf.Bytes()))
}
开发者ID:shizhh,项目名称:lantern,代码行数:27,代码来源:wfilter_test.go


示例8: TestCreateAndRefresh

func TestCreateAndRefresh(t *testing.T) {
	if true {
		t.Log("We don't currently use peerscanner, so this test is disabled. To reenable, we'll need to delete test distributions to avoid hitting our limit")
		return
	}
	_, counter, err := fdcount.Matching("TCP")
	if err != nil {
		t.Fatalf("Unable to get starting fdcount: %v", err)
	}
	cfr := getCfr()
	// Deleting cloudfront distributions is actually quite an involved process.
	// Fortunately, distributions per se cost us nothing.  A separate service
	// will be implemented to delete test and otherwise unused distributions.
	name := uuid.NewV4().String()
	dist, err := CreateDistribution(cfr, name, name+"-grey.flashlightproxy.org", COMMENT)
	assert.NoError(t, err, "Should be able to create distribution")
	assert.Equal(t, "InProgress", dist.Status, "New distribution should have Status: \"InProgress\"")
	assert.Equal(t, dist.Comment, COMMENT, "New distribution should have the comment we've set for it")
	assert.Equal(t, name, dist.InstanceId, "New distribution should have the right InstanceId")
	assert.True(t, strings.HasSuffix(dist.Domain, ".cloudfront.net"), "Domain should be a .cloudfront.net subdomain, not '"+dist.Domain+"'")
	dist.Status = "modified to check it really gets overwritten"
	err = RefreshStatus(cfr, dist)
	assert.NoError(t, err, "Should be able to refresh status")
	// Just check that Status stays a valid one.  Checking that it eventually
	// gets refreshed to "Deployed" would take a few minutes, and thus is out
	// of the scope of this unit test.
	assert.Equal(t, "InProgress", dist.Status, "New distribution should have Status: \"InProgress\" even after refreshing right away")
	assert.NoError(t, counter.AssertDelta(0), "All file descriptors should have been closed")
}
开发者ID:2722,项目名称:lantern,代码行数:29,代码来源:cfr_test.go


示例9: TestIgnoreEmpty

func TestIgnoreEmpty(t *testing.T) {
	tarString := bytes.NewBuffer(nil)
	err := EncodeToTarString("resources", tarString)
	if err != nil {
		t.Fatalf("Unable to encode to tar string: %v", err)
	}

	fs, err := New(tarStringToBytes(t, tarString), "localresources")
	if err != nil {
		t.Fatalf("Unable to open filesystem: %v", err)
	}

	// Test to make sure we get the file if we're not ignoring empty.
	// Note empty on disk actually has a single space to allow us to
	// check it into git, but the method ignores whitespace.
	a, err := fs.Get("empty.txt")
	if assert.NoError(t, err, "empty.txt should have loaded") {
		assert.Equal(t, " \n", string(a), "A should have matched expected")
	}

	// We artificially change the entry for empty byte in the file system
	// to make sure we get the file system and not the local version.
	emptyBytes := []byte("empty")
	fs.files["empty.txt"] = emptyBytes

	a, err = fs.GetIgnoreLocalEmpty("empty.txt")
	if assert.NoError(t, err, "empty.txt should have loaded") {
		assert.Equal(t, string(emptyBytes), string(a), "A should have matched expected")
	}
}
开发者ID:Christeefym,项目名称:lantern,代码行数:30,代码来源:tarfs_test.go


示例10: TestSuccess

func TestSuccess(t *testing.T) {
	text, timedOut, err := Do(1*time.Second, func() (interface{}, error) {
		return expectedText, expectedErr
	})
	assert.False(t, timedOut, "Should not have timed out")
	assert.Equal(t, expectedText, text, "Text should match expected")
	assert.Equal(t, expectedErr, err, "Error should match expected")
}
开发者ID:2722,项目名称:lantern,代码行数:8,代码来源:withtimeout_test.go


示例11: TestConfigServer

func TestConfigServer(t *testing.T) {
	file, err := ioutil.TempFile("", "yamlconf_test_")
	if err != nil {
		t.Fatalf("Unable to create temp file: %s", err)
	}
	defer os.Remove(file.Name())

	m := &Manager{
		EmptyConfig: func() Config {
			return &TestCfg{}
		},
		FilePath:         file.Name(),
		FilePollInterval: pollInterval,
		ConfigServerAddr: ConfigSrvAddr,
	}

	_, err = m.Init()
	if err != nil {
		t.Fatalf("Unable to init manager: %s", err)
	}
	m.StartPolling()

	newNested := &Nested{
		S: "900",
		I: 900,
	}
	nny, err := yaml.Marshal(newNested)
	if err != nil {
		t.Fatalf("Unable to marshal new nested into yaml: %s", err)
	}

	_, err = http.Post(fmt.Sprintf("http://%s/N", ConfigSrvAddr), "text/yaml", bytes.NewReader(nny))
	assert.NoError(t, err, "POSTing to config server should succeed")

	updated := m.Next()

	assert.Equal(t, &TestCfg{
		Version: 2,
		N:       newNested,
	}, updated, "Nested should have been updated by POST")

	req, err := http.NewRequest("DELETE", fmt.Sprintf("http://%s/N/I", ConfigSrvAddr), bytes.NewReader(nny))
	if err != nil {
		t.Fatalf("Unable to construct DELETE request: %s", err)
	}
	_, err = (&http.Client{}).Do(req)
	assert.NoError(t, err, "DELETEing to config server should succeed")

	updated = m.Next()

	assert.Equal(t, &TestCfg{
		Version: 3,
		N: &Nested{
			S: newNested.S,
			I: FIXED_I,
		},
	}, updated, "Nested I should have reverted to default value after clearing")
}
开发者ID:shizhh,项目名称:lantern,代码行数:58,代码来源:yamlconf_test.go


示例12: TestWriteTooLong

func TestWriteTooLong(t *testing.T) {
	w := NewWriter(ioutil.Discard)
	b := make([]byte, MaxFrameLength+1)
	n, err := w.Write(b)
	assert.Error(t, err, "Writing too long message should result in error")
	assert.Equal(t, 0, n, "Writing too long message should result in 0 bytes written")
	n, err = w.Write(b[:len(b)-1])
	assert.NoError(t, err, "Writing message of MaxFrameLength should be allowed")
	assert.Equal(t, MaxFrameLength, n, "Writing message of MaxFrameLength should have written MaxFrameLength bytes")
}
开发者ID:mijo-sjx,项目名称:lantern,代码行数:10,代码来源:framed_test.go


示例13: TestRoundTrip

func TestRoundTrip(t *testing.T) {
	defer func() {
		if err := os.Remove(PK_FILE); err != nil {
			log.Debugf("Unable to remove file: %v", err)
		}
	}()
	defer func() {
		if err := os.Remove(CERT_FILE); err != nil {
			log.Debugf("Unable to remove file: %v", err)
		}
	}()

	pk, err := GeneratePK(1024)
	assert.NoError(t, err, "Unable to generate PK")

	err = pk.WriteToFile(PK_FILE)
	assert.NoError(t, err, "Unable to save PK")

	pk2, err := LoadPKFromFile(PK_FILE)
	assert.NoError(t, err, "Unable to load PK")
	assert.Equal(t, pk.PEMEncoded(), pk2.PEMEncoded(), "Loaded PK didn't match saved PK")

	cert, err := pk.TLSCertificateFor("Test Org", "127.0.0.1", time.Now().Add(TWO_WEEKS), true, nil)
	assert.NoError(t, err, "Unable to generate self-signed certificate")

	numberOfIPSANs := len(cert.X509().IPAddresses)
	if numberOfIPSANs != 1 {
		t.Errorf("Wrong number of SANs, expected 1 got %d", numberOfIPSANs)
	} else {
		ip := cert.X509().IPAddresses[0]
		expectedIP := net.ParseIP("127.0.0.1")
		assert.Equal(t, expectedIP.String(), ip.String(), "Wrong IP SAN")
	}

	err = cert.WriteToFile(CERT_FILE)
	assert.NoError(t, err, "Unable to write certificate to file")

	cert2, err := LoadCertificateFromFile(CERT_FILE)
	assert.NoError(t, err, "Unable to load certificate from file")
	assert.Equal(t, cert.PEMEncoded(), cert2.PEMEncoded(), "Loaded certificate didn't match saved certificate")

	_, err = pk.Certificate(cert.X509(), cert)
	assert.NoError(t, err, "Unable to generate certificate signed by original certificate")

	pk3, err := GeneratePK(1024)
	assert.NoError(t, err, "Unable to generate PK 3")

	_, err = pk.CertificateForKey(cert.X509(), cert, &pk3.rsaKey.PublicKey)
	assert.NoError(t, err, "Unable to generate certificate for pk3")

	x509rt, err := LoadCertificateFromX509(cert.X509())
	assert.NoError(t, err, "Unable to load certificate from X509")
	assert.Equal(t, cert, x509rt, "X509 round tripped cert didn't match original")
}
开发者ID:2722,项目名称:lantern,代码行数:54,代码来源:keyman_test.go


示例14: TestSimplePrepender

func TestSimplePrepender(t *testing.T) {
	buf := bytes.NewBuffer(nil)
	w := SimplePrepender(buf, func(w io.Writer) (int, error) {
		return fmt.Fprintf(w, "++ ")
	})

	n, err := fmt.Fprint(w, "##")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 5, n, "Wrong bytes written for A")
	}

	n, err = fmt.Fprint(w, "##\n\n")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 7, n, "Wrong bytes written for A")
	}

	n, err = fmt.Fprint(w, "\n\n##\n\n")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 9, n, "Wrong bytes written for A")
	}

	w = SimplePrepender(buf, func(w io.Writer) (int, error) {
		return fmt.Fprintf(w, "")
	})

	n, err = fmt.Fprint(w, "##")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 2, n, "Wrong bytes written for A")
	}

	n, err = fmt.Fprint(w, "##\n\n")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 4, n, "Wrong bytes written for A")
	}

	n, err = fmt.Fprint(w, "\n\n##\n\n")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 6, n, "Wrong bytes written for A")
	}

	w = SimplePrepender(buf, func(w io.Writer) (int, error) {
		return fmt.Fprintf(w, "\n\n")
	})

	n, err = fmt.Fprint(w, "##")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 4, n, "Wrong bytes written for A")
	}

	n, err = fmt.Fprint(w, "##\n\n")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 6, n, "Wrong bytes written for A")
	}

	n, err = fmt.Fprint(w, "\n\n##\n\n")
	if assert.NoError(t, err, "Error writing A") {
		assert.Equal(t, 8, n, "Wrong bytes written for A")
	}
}
开发者ID:2722,项目名称:lantern,代码行数:59,代码来源:wfilter_test.go


示例15: compareReports

func compareReports(t *testing.T, expected report, actual report, index string) {
	expectedDims := expected["dims"].(map[string]string)
	actualDims := actual["dims"].(map[string]string)

	assert.Equal(t, expectedDims["a"], actualDims["a"], fmt.Sprintf("On %s, dim a should match", index))
	assert.Equal(t, expectedDims["b"], actualDims["b"], fmt.Sprintf("On %s, dim b should match", index))

	assert.Equal(t, expected["increments"], actual["increments"], fmt.Sprintf("On %s, increments should match", index))
	assert.Equal(t, expected["gauges"], actual["gauges"], fmt.Sprintf("On %s, gauges should match", index))
	assert.Equal(t, expected["multiMembers"], actual["multiMembers"], fmt.Sprintf("On %s, members should match", index))
}
开发者ID:kidaa,项目名称:lantern,代码行数:11,代码来源:statreporter_test.go


示例16: Test

// Test tests a Dialer.
func Test(t *testing.T, dialer Dialer) {
	// Set up listener for server endpoint
	sl, err := net.Listen("tcp", "localhost:0")
	if err != nil {
		t.Fatalf("Unable to listen: %s", err)
	}

	// Server that responds to ping
	go func() {
		conn, err := sl.Accept()
		if err != nil {
			t.Fatalf("Unable to accept connection: %s", err)
			return
		}
		defer func() {
			if err := conn.Close(); err != nil {
				t.Logf("Unable to close connection: %v", err)
			}
		}()
		b := make([]byte, 4)
		_, err = io.ReadFull(conn, b)
		if err != nil {
			t.Fatalf("Unable to read from client: %s", err)
		}
		assert.Equal(t, ping, b, "Didn't receive correct ping message")
		_, err = conn.Write(pong)
		if err != nil {
			t.Fatalf("Unable to write to client: %s", err)
		}
	}()

	conn, err := dialer.Dial("connect", sl.Addr().String())
	if err != nil {
		t.Fatalf("Unable to dial via proxy: %s", err)
	}
	defer func() {
		if err := conn.Close(); err != nil {
			t.Logf("Unable to close connection: %v", err)
		}
	}()

	_, err = conn.Write(ping)
	if err != nil {
		t.Fatalf("Unable to write to server via proxy: %s", err)
	}

	b := make([]byte, 4)
	_, err = io.ReadFull(conn, b)
	if err != nil {
		t.Fatalf("Unable to read from server: %s", err)
	}
	assert.Equal(t, pong, b, "Didn't receive correct pong message")
}
开发者ID:Christeefym,项目名称:lantern,代码行数:54,代码来源:proxy.go


示例17: doTestPlainText

func doTestPlainText(buffered bool, useHostFn bool, t *testing.T) {
	var counter *fdcount.Counter
	var err error

	startServers(t, useHostFn)

	err = fdcount.WaitUntilNoneMatch("CLOSE_WAIT", 5*time.Second)
	if err != nil {
		t.Fatalf("Unable to wait until no more connections are in CLOSE_WAIT: %v", err)
	}

	_, counter, err = fdcount.Matching("TCP")
	if err != nil {
		t.Fatalf("Unable to get fdcount: %v", err)
	}

	var reportedHost string
	var reportedHostMutex sync.Mutex
	onResponse := func(resp *http.Response) {
		reportedHostMutex.Lock()
		reportedHost = resp.Header.Get(X_ENPROXY_PROXY_HOST)
		reportedHostMutex.Unlock()
	}

	conn, err := prepareConn(httpAddr, buffered, false, t, onResponse)
	if err != nil {
		t.Fatalf("Unable to prepareConn: %s", err)
	}
	defer func() {
		err := conn.Close()
		assert.Nil(t, err, "Closing conn should succeed")
		if !assert.NoError(t, counter.AssertDelta(2), "All file descriptors except the connection from proxy to destination site should have been closed") {
			DumpConnTrace()
		}
	}()

	doRequests(conn, t)

	assert.Equal(t, 208, bytesReceived, "Wrong number of bytes received")
	assert.Equal(t, 284, bytesSent, "Wrong number of bytes sent")
	assert.True(t, destsSent[httpAddr], "http address wasn't recorded as sent destination")
	assert.True(t, destsReceived[httpAddr], "http address wasn't recorded as received destination")

	reportedHostMutex.Lock()
	rh := reportedHost
	reportedHostMutex.Unlock()
	assert.Equal(t, "localhost", rh, "Didn't get correct reported host")
}
开发者ID:shizhh,项目名称:lantern,代码行数:48,代码来源:conn_test.go


示例18: TestStringOK

func TestStringOK(t *testing.T) {
	id1 := Random()
	id1String := id1.String()
	id2, err := FromString(id1String)
	assert.NoError(t, err, "Unable to read from string")
	assert.Equal(t, id1.ToBytes(), id2.ToBytes(), "Read didn't match written")
}
开发者ID:2722,项目名称:lantern,代码行数:7,代码来源:buuid_test.go


示例19: connectAndRead

func connectAndRead(t *testing.T, p Pool, loops int) {
	var wg sync.WaitGroup

	for i := 0; i < loops; i++ {
		wg.Add(1)

		func(wg *sync.WaitGroup) {
			c, err := p.Get()
			if err != nil {
				t.Fatalf("Error getting connection: %s", err)
			}
			read, err := ioutil.ReadAll(c)
			if err != nil {
				t.Fatalf("Error reading from connection: %s", err)
			}
			assert.Equal(t, msg, read, "Should have received %s from server", string(msg))
			if err := c.Close(); err != nil {
				t.Fatalf("Unable to close connection: %v", err)
			}

			wg.Done()
		}(&wg)
	}

	wg.Wait()
}
开发者ID:2722,项目名称:lantern,代码行数:26,代码来源:connpool_test.go


示例20: TestTCP

func TestTCP(t *testing.T) {
	// Lower maxAssertAttempts to keep this test from running too long
	maxAssertAttempts = 2

	l0, err := net.Listen("tcp", "localhost:0")
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		if err := l0.Close(); err != nil {
			t.Fatalf("Unable to close listener: %v", err)
		}
	}()

	start, fdc, err := Matching("TCP")
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, 1, start, "Starting count should have been 1")

	err = fdc.AssertDelta(0)
	if err != nil {
		t.Fatal(err)
	}
	assert.NoError(t, err, "Initial TCP count should be 0")

	l, err := net.Listen("tcp", "localhost:0")
	if err != nil {
		t.Fatal(err)
	}
	_, middle, err := Matching("TCP")
	if err != nil {
		t.Fatal(err)
	}

	err = fdc.AssertDelta(0)
	if assert.Error(t, err, "Asserting wrong count should fail") {
		assert.Contains(t, err.Error(), "Expected 0, have 1")
		assert.True(t, len(err.Error()) > 100)
	}
	err = fdc.AssertDelta(1)
	assert.NoError(t, err, "Ending TCP count should be 1")

	err = fdc.AssertDelta(0)
	if assert.Error(t, err, "Asserting wrong count should fail") {
		assert.Contains(t, err.Error(), "Expected 0, have 1")
		assert.Contains(t, err.Error(), "New")
		assert.True(t, len(err.Error()) > 100)
	}

	if err := l.Close(); err != nil {
		t.Fatalf("Unable to close listener: %v", err)
	}
	err = middle.AssertDelta(0)
	if assert.Error(t, err, "Asserting wrong count should fail") {
		assert.Contains(t, err.Error(), "Expected 0, have -1")
		assert.Contains(t, err.Error(), "Removed")
		assert.True(t, len(err.Error()) > 100)
	}
}
开发者ID:2722,项目名称:lantern,代码行数:60,代码来源:fdcount_test.go



注:本文中的github.com/getlantern/testify/assert.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang assert.Error函数代码示例发布时间:2022-05-23
下一篇:
Golang golog.LoggerFor函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap