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

Golang testing.T类代码示例

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

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



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

示例1: TestByExcludeReason_Less

func TestByExcludeReason_Less(t *testing.T) {
	m := Mirrors{
		Mirror{
			ID:            "M0",
			ExcludeReason: "x42",
		},
		Mirror{
			ID:            "M1",
			ExcludeReason: "x43",
		},
		Mirror{
			ID:            "M2",
			ExcludeReason: "Test one",
		},
		Mirror{
			ID:            "M3",
			ExcludeReason: "Test two",
		},
		Mirror{
			ID:            "M4",
			ExcludeReason: "test three",
		},
	}

	sort.Sort(ByExcludeReason{m})

	if !matchingMirrorOrder(m, []string{"M2", "M3", "M4", "M0", "M1"}) {
		t.Fatalf("Order doesn't seem right: %s, expected M2, M3, M4, M0, M1", formatMirrorOrder(m))
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:30,代码来源:mirrors_test.go


示例2: TestMarkMirrorDown

func TestMarkMirrorDown(t *testing.T) {
	_, conn := PrepareRedisTest()

	if err := MarkMirrorDown(conn, "m1", "test1"); err == nil {
		t.Fatalf("Error expected but nil returned")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:7,代码来源:mirrors_test.go


示例3: TestByComputedScore_Less

func TestByComputedScore_Less(t *testing.T) {
	m := Mirrors{
		Mirror{
			ID:            "M0",
			ComputedScore: 50,
		},
		Mirror{
			ID:            "M1",
			ComputedScore: 0,
		},
		Mirror{
			ID:            "M2",
			ComputedScore: 2500,
		},
		Mirror{
			ID:            "M3",
			ComputedScore: 21,
		},
	}

	sort.Sort(ByComputedScore{m})

	if !matchingMirrorOrder(m, []string{"M2", "M0", "M3", "M1"}) {
		t.Fatalf("Order doesn't seem right: %s, expected M2, M0, M3, M1", formatMirrorOrder(m))
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:26,代码来源:mirrors_test.go


示例4: TestMirrors_Len

func TestMirrors_Len(t *testing.T) {
	m := Mirrors{}
	if m.Len() != 0 {
		t.Fatalf("Expected 0, got %d", m.Len())
	}

	m = generateSimpleMirrorList(2)
	if m.Len() != len(m) {
		t.Fatalf("Expected %d, got %d", len(m), m.Len())
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:11,代码来源:mirrors_test.go


示例5: TestNewCache

func TestNewCache(t *testing.T) {
	_, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(nil)
	if c != nil {
		t.Fatalf("Expected invalid instance")
	}

	c = NewCache(conn)
	if c == nil {
		t.Fatalf("No valid instance returned")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:14,代码来源:cache_test.go


示例6: TestCache_Clear

func TestCache_Clear(t *testing.T) {
	_, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(conn)

	c.fiCache.Set("test", &TestValue{"42"})
	c.fmCache.Set("test", &TestValue{"42"})
	c.mCache.Set("test", &TestValue{"42"})
	c.fimCache.Set("test", &TestValue{"42"})

	c.Clear()

	if _, ok := c.fiCache.Get("test"); ok {
		t.Fatalf("Value shouldn't be present")
	}
	if _, ok := c.fmCache.Get("test"); ok {
		t.Fatalf("Value shouldn't be present")
	}
	if _, ok := c.mCache.Get("test"); ok {
		t.Fatalf("Value shouldn't be present")
	}
	if _, ok := c.fimCache.Get("test"); ok {
		t.Fatalf("Value shouldn't be present")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:26,代码来源:cache_test.go


示例7: TestDisableMirror

func TestDisableMirror(t *testing.T) {
	mock, conn := PrepareRedisTest()

	cmd_disable := mock.Command("HMSET", "MIRROR_m1", "enabled", false).Expect("ok")
	DisableMirror(conn, "m1")

	if mock.Stats(cmd_disable) != 1 {
		t.Fatalf("Mirror not enabled")
	}

	mock.Command("HMSET", "MIRROR_m1", "enabled", false).ExpectError(redis.Error("blah"))
	if DisableMirror(conn, "m1") == nil {
		t.Fatalf("Error expected")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:15,代码来源:mirrors_test.go


示例8: TestCache_GetMirror

func TestCache_GetMirror(t *testing.T) {
	mock, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(conn)

	testmirror := "m1"

	_, err := c.GetMirror(testmirror)
	if err == nil {
		t.Fatalf("Error expected, mock command not yet registered")
	}

	cmd_get_mirror := mock.Command("HGETALL", "MIRROR_m1").ExpectMap(map[string]string{
		"ID": testmirror,
	})

	m, err := c.GetMirror(testmirror)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err.Error())
	}

	if mock.Stats(cmd_get_mirror) < 1 {
		t.Fatalf("HGETALL not executed")
	}

	// Results are already checked by TestCache_fetchMirror
	// We only need to check one of them
	if m.ID != testmirror {
		t.Fatalf("Result is different")
	}

	_, ok := c.mCache.Get(testmirror)
	if !ok {
		t.Fatalf("Not stored in cache")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:37,代码来源:cache_test.go


示例9: TestCache_fetchFileMirrors

func TestCache_fetchFileMirrors(t *testing.T) {
	mock, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(conn)
	filename := "/test/file.tgz"

	_, err := c.fetchFileMirrors(filename)
	if err == nil {
		t.Fatalf("Error expected, mock command not yet registered")
	}

	cmd_get_filemirrors := mock.Command("SMEMBERS", "FILEMIRRORS_"+filename).Expect([]interface{}{
		[]byte("m9"),
		[]byte("m2"),
		[]byte("m5"),
	})

	ids, err := c.fetchFileMirrors(filename)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err.Error())
	}

	if mock.Stats(cmd_get_filemirrors) < 1 {
		t.Fatalf("SMEMBERS not executed")
	}

	if len(ids) != 3 {
		t.Fatalf("Invalid number of items returned")
	}

	_, ok := c.fmCache.Get(filename)
	if !ok {
		t.Fatalf("Not stored in cache")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:36,代码来源:cache_test.go


示例10: TestCache_fetchFileInfoMirror

func TestCache_fetchFileInfoMirror(t *testing.T) {
	mock, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(conn)

	testfile := filesystem.FileInfo{
		Path:    "/test/file.tgz",
		Size:    44000,
		ModTime: time.Now(),
		Sha1:    "3ce963aea2d6f23fe915063f8bba21888db0ddfa",
		Sha256:  "1c8e38c7e03e4d117eba4f82afaf6631a9b79f4c1e9dec144d4faf1d109aacda",
		Md5:     "2c98ec39f49da6ddd9cfa7b1d7342afe",
	}

	_, err := c.fetchFileInfoMirror("m1", testfile.Path)
	if err == nil {
		t.Fatalf("Error expected, mock command not yet registered")
	}

	cmd_get_fileinfomirror := mock.Command("HMGET", "FILEINFO_m1_"+testfile.Path, "size", "modTime", "sha1", "sha256", "md5").ExpectMap(map[string]string{
		"size":    strconv.FormatInt(testfile.Size, 10),
		"modTime": testfile.ModTime.String(),
		"sha1":    testfile.Sha1,
		"sha256":  testfile.Sha256,
		"md5":     testfile.Md5,
	})

	_, err = c.fetchFileInfoMirror("m1", testfile.Path)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err.Error())
	}

	if mock.Stats(cmd_get_fileinfomirror) < 1 {
		t.Fatalf("HGETALL not executed")
	}

	_, ok := c.fimCache.Get("m1|" + testfile.Path)
	if !ok {
		t.Fatalf("Not stored in cache")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:42,代码来源:cache_test.go


示例11: TestGetMirrorMapUrl

func TestGetMirrorMapUrl(t *testing.T) {
	m := Mirrors{
		Mirror{
			ID:        "M0",
			Latitude:  -80.0,
			Longitude: 80.0,
		},
		Mirror{
			ID:        "M1",
			Latitude:  -60.0,
			Longitude: 60.0,
		},
		Mirror{
			ID:        "M2",
			Latitude:  -40.0,
			Longitude: 40.0,
		},
		Mirror{
			ID:        "M3",
			Latitude:  -20.0,
			Longitude: 20.0,
		},
	}

	c := network.GeoIPRecord{
		GeoIPRecord: &geoip.GeoIPRecord{
			Latitude:  -10.0,
			Longitude: 10.0,
		},
		ASNum: 4444,
	}

	result := GetMirrorMapUrl(m, c)

	if !strings.HasPrefix(result, "//maps.googleapis.com") {
		t.Fatalf("Bad format")
	}

	if !strings.Contains(result, "color:red") {
		t.Fatalf("Missing client marker?")
	}

	if strings.Count(result, "label:") != len(m) {
		t.Fatalf("Missing some mirror markers?")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:46,代码来源:mirrors_test.go


示例12: TestMirrors_Swap

func TestMirrors_Swap(t *testing.T) {
	m := generateSimpleMirrorList(5)

	if !matchingMirrorOrder(m, []string{"M0", "M1", "M2", "M3", "M4"}) {
		t.Fatalf("Expected M0 before M1, got %s", formatMirrorOrder(m))
	}

	m.Swap(0, 1)

	if !matchingMirrorOrder(m, []string{"M1", "M0", "M2", "M3", "M4"}) {
		t.Fatalf("Expected M1 before M0, got %s", formatMirrorOrder(m))
	}

	m.Swap(2, 4)

	if !matchingMirrorOrder(m, []string{"M1", "M0", "M4", "M3", "M2"}) {
		t.Fatalf("Expected M4 at position 2 and M2 at position 4", m)
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:19,代码来源:mirrors_test.go


示例13: TestCache_fetchFileInfo

func TestCache_fetchFileInfo(t *testing.T) {
	mock, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(conn)

	testfile := filesystem.FileInfo{
		Path:    "/test/file.tgz",
		Size:    43000,
		ModTime: time.Now(),
		Sha1:    "3ce963aea2d6f23fe915063f8bba21888db0ddfa",
		Sha256:  "1c8e38c7e03e4d117eba4f82afaf6631a9b79f4c1e9dec144d4faf1d109aacda",
		Md5:     "2c98ec39f49da6ddd9cfa7b1d7342afe",
	}

	f, err := c.fetchFileInfo(testfile.Path)
	if err == nil {
		t.Fatalf("Error expected, mock command not yet registered")
	}

	cmd_get_fileinfo := mock.Command("HMGET", "FILE_"+testfile.Path, "size", "modTime", "sha1", "sha256", "md5").Expect([]interface{}{
		[]byte(strconv.FormatInt(testfile.Size, 10)),
		[]byte(testfile.ModTime.String()),
		[]byte(testfile.Sha1),
		[]byte(testfile.Sha256),
		[]byte(testfile.Md5),
	})

	f, err = c.fetchFileInfo(testfile.Path)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err.Error())
	}

	if mock.Stats(cmd_get_fileinfo) < 1 {
		t.Fatalf("HMGET not executed")
	}

	if f.Path != testfile.Path {
		t.Fatalf("Path doesn't match, expected %#v got %#v", testfile.Path, f.Path)
	}
	if f.Size != testfile.Size {
		t.Fatalf("Size doesn't match, expected %#v got %#v", testfile.Size, f.Size)
	}
	if f.ModTime != testfile.ModTime {
		t.Fatalf("ModTime doesn't match, expected %#v got %#v", testfile.ModTime, f.ModTime)
	}
	if f.Sha1 != testfile.Sha1 {
		t.Fatalf("Sha1 doesn't match, expected %#v got %#v", testfile.Sha1, f.Sha1)
	}
	if f.Sha256 != testfile.Sha256 {
		t.Fatalf("Sha256 doesn't match, expected %#v got %#v", testfile.Sha256, f.Sha256)
	}
	if f.Md5 != testfile.Md5 {
		t.Fatalf("Md5 doesn't match, expected %#v got %#v", testfile.Md5, f.Md5)
	}

	_, ok := c.fiCache.Get(testfile.Path)
	if !ok {
		t.Fatalf("Not stored in cache")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:61,代码来源:cache_test.go


示例14: TestSetMirrorState

func TestSetMirrorState(t *testing.T) {
	mock, conn := PrepareRedisTest()

	if err := SetMirrorState(conn, "m1", true, "test1"); err == nil {
		t.Fatalf("Error expected but nil returned")
	}

	cmd_publish := mock.Command("PUBLISH", string(database.MIRROR_UPDATE), redigomock.NewAnyData()).Expect("ok")

	/* */

	cmd_previous_state := mock.Command("HGET", "MIRROR_m1", "up").Expect(int64(0)).Expect(int64(1))
	cmd_state_since := mock.Command("HMSET", "MIRROR_m1", "up", true, "excludeReason", "test1", "stateSince", redigomock.NewAnyInt()).Expect("ok")
	cmd_state := mock.Command("HMSET", "MIRROR_m1", "up", true, "excludeReason", "test2").Expect("ok")

	if err := SetMirrorState(conn, "m1", true, "test1"); err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}

	if mock.Stats(cmd_previous_state) < 1 {
		t.Fatalf("Previous state not tested")
	}

	if mock.Stats(cmd_state_since) < 1 {
		t.Fatalf("New state not set")
	} else if mock.Stats(cmd_state_since) > 1 {
		t.Fatalf("State set more than once")
	}

	if mock.Stats(cmd_publish) < 1 {
		t.Fatalf("Event MIRROR_UPDATE not published")
	}

	/* */

	if err := SetMirrorState(conn, "m1", true, "test2"); err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}

	if mock.Stats(cmd_state_since) > 1 || mock.Stats(cmd_state) < 1 {
		t.Fatalf("The value stateSince isn't supposed to be set")
	}

	if mock.Stats(cmd_publish) != 1 {
		t.Fatalf("Event MIRROR_UPDATE should not be sent")
	}

	/* */

	cmd_previous_state = mock.Command("HGET", "MIRROR_m1", "up").Expect(int64(1))
	cmd_state_since = mock.Command("HMSET", "MIRROR_m1", "up", false, "excludeReason", "test3", "stateSince", redigomock.NewAnyInt()).Expect("ok")

	if err := SetMirrorState(conn, "m1", false, "test3"); err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}

	if mock.Stats(cmd_previous_state) < 1 {
		t.Fatalf("Previous state not tested")
	}

	if mock.Stats(cmd_state_since) < 1 {
		t.Fatalf("New state not set")
	} else if mock.Stats(cmd_state_since) > 1 {
		t.Fatalf("State set more than once")
	}

	if mock.Stats(cmd_publish) < 2 {
		t.Fatalf("Event MIRROR_UPDATE not published")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:70,代码来源:mirrors_test.go


示例15: TestSetMirrorEnabled

func TestSetMirrorEnabled(t *testing.T) {
	mock, conn := PrepareRedisTest()

	cmd_publish := mock.Command("PUBLISH", string(database.MIRROR_UPDATE), redigomock.NewAnyData()).Expect("ok")

	cmd_enable := mock.Command("HMSET", "MIRROR_m1", "enabled", true).Expect("ok")
	SetMirrorEnabled(conn, "m1", true)

	if mock.Stats(cmd_enable) < 1 {
		t.Fatalf("Mirror not enabled")
	} else if mock.Stats(cmd_enable) > 1 {
		t.Fatalf("Mirror enabled more than once")
	}

	if mock.Stats(cmd_publish) < 1 {
		t.Fatalf("Event MIRROR_UPDATE not published")
	}

	mock.Command("HMSET", "MIRROR_m1", "enabled", true).ExpectError(redis.Error("blah"))
	if SetMirrorEnabled(conn, "m1", true) == nil {
		t.Fatalf("Error expected")
	}

	cmd_disable := mock.Command("HMSET", "MIRROR_m1", "enabled", false).Expect("ok")
	SetMirrorEnabled(conn, "m1", false)

	if mock.Stats(cmd_disable) != 1 {
		t.Fatalf("Mirror not disabled")
	} else if mock.Stats(cmd_disable) > 1 {
		t.Fatalf("Mirror disabled more than once")
	}

	if mock.Stats(cmd_publish) < 2 {
		t.Fatalf("Event MIRROR_UPDATE not published")
	}

	mock.Command("HMSET", "MIRROR_m1", "enabled", false).ExpectError(redis.Error("blah"))
	if SetMirrorEnabled(conn, "m1", false) == nil {
		t.Fatalf("Error expected")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:41,代码来源:mirrors_test.go


示例16: TestCache_fetchMirror

func TestCache_fetchMirror(t *testing.T) {
	mock, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(conn)

	testmirror := Mirror{
		ID:             "m1",
		HttpURL:        "http://m1.mirror",
		RsyncURL:       "rsync://m1.mirror",
		FtpURL:         "ftp://m1.mirror",
		SponsorName:    "m1sponsor",
		SponsorURL:     "m1sponsorurl",
		SponsorLogoURL: "m1sponsorlogourl",
		AdminName:      "m1adminname",
		AdminEmail:     "m1adminemail",
		CustomData:     "m1customdata",
		ContinentOnly:  true,
		CountryOnly:    false,
		ASOnly:         true,
		Score:          0,
		Latitude:       -20.0,
		Longitude:      55.0,
		ContinentCode:  "EU",
		CountryCodes:   "FR UK",
		Asnum:          444,
		Comment:        "m1comment",
		Enabled:        true,
		Up:             true,
	}

	_, err := c.fetchMirror(testmirror.ID)
	if err == nil {
		t.Fatalf("Error expected, mock command not yet registered")
	}

	cmd_get_mirror := mock.Command("HGETALL", "MIRROR_m1").ExpectMap(map[string]string{
		"ID":            testmirror.ID,
		"http":          testmirror.HttpURL,
		"rsync":         testmirror.RsyncURL,
		"ftp":           testmirror.FtpURL,
		"sponsorName":   testmirror.SponsorName,
		"sponsorURL":    testmirror.SponsorURL,
		"sponsorLogo":   testmirror.SponsorLogoURL,
		"adminName":     testmirror.AdminName,
		"adminEmail":    testmirror.AdminEmail,
		"customData":    testmirror.CustomData,
		"continentOnly": strconv.FormatBool(testmirror.ContinentOnly),
		"countryOnly":   strconv.FormatBool(testmirror.CountryOnly),
		"asOnly":        strconv.FormatBool(testmirror.ASOnly),
		"score":         strconv.FormatInt(int64(testmirror.Score), 10),
		"latitude":      fmt.Sprintf("%f", testmirror.Latitude),
		"longitude":     fmt.Sprintf("%f", testmirror.Longitude),
		"continentCode": testmirror.ContinentCode,
		"countryCodes":  testmirror.CountryCodes,
		"asnum":         strconv.FormatInt(int64(testmirror.Asnum), 10),
		"comment":       testmirror.Comment,
		"enabled":       strconv.FormatBool(testmirror.Enabled),
		"up":            strconv.FormatBool(testmirror.Up),
	})

	m, err := c.fetchMirror(testmirror.ID)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err.Error())
	}

	if mock.Stats(cmd_get_mirror) < 1 {
		t.Fatalf("HGETALL not executed")
	}

	// This is required to reach DeepEqual(ity)
	testmirror.CountryFields = strings.Fields(testmirror.CountryCodes)

	if !reflect.DeepEqual(testmirror, m) {
		t.Fatalf("Result is different")
	}

	_, ok := c.mCache.Get(testmirror.ID)
	if !ok {
		t.Fatalf("Not stored in cache")
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:82,代码来源:cache_test.go


示例17: TestCache_GetMirrors

func TestCache_GetMirrors(t *testing.T) {
	mock, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(conn)

	filename := "/test/file.tgz"

	clientInfo := network.GeoIPRecord{
		GeoIPRecord: &geoip.GeoIPRecord{
			CountryCode: "FR",
			Latitude:    48.8567,
			Longitude:   2.3508,
		},
	}

	_, err := c.GetMirrors(filename, clientInfo)
	if err == nil {
		t.Fatalf("Error expected, mock command not yet registered")
	}

	cmd_get_filemirrors := mock.Command("SMEMBERS", "FILEMIRRORS_"+filename).Expect([]interface{}{
		[]byte("m1"),
		[]byte("m2"),
	})

	cmd_get_mirror_m1 := mock.Command("HGETALL", "MIRROR_m1").ExpectMap(map[string]string{
		"ID":        "m1",
		"latitude":  "52.5167",
		"longitude": "13.3833",
	})

	cmd_get_mirror_m2 := mock.Command("HGETALL", "MIRROR_m2").ExpectMap(map[string]string{
		"ID":        "m2",
		"latitude":  "51.5072",
		"longitude": "0.1275",
	})

	cmd_get_fileinfomirror_m1 := mock.Command("HMGET", "FILEINFO_m1_"+filename, "size", "modTime", "sha1", "sha256", "md5").ExpectMap(map[string]string{
		"size":    "44000",
		"modTime": "",
		"sha1":    "",
		"sha256":  "",
		"md5":     "",
	})

	cmd_get_fileinfomirror_m2 := mock.Command("HMGET", "FILEINFO_m2_"+filename, "size", "modTime", "sha1", "sha256", "md5").ExpectMap(map[string]string{
		"size":    "44000",
		"modTime": "",
		"sha1":    "",
		"sha256":  "",
		"md5":     "",
	})

	mirrors, err := c.GetMirrors(filename, clientInfo)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err.Error())
	}

	if mock.Stats(cmd_get_filemirrors) < 1 {
		t.Fatalf("cmd_get_filemirrors not called")
	}
	if mock.Stats(cmd_get_mirror_m1) < 1 {
		t.Fatalf("cmd_get_mirror_m1 not called")
	}
	if mock.Stats(cmd_get_mirror_m2) < 1 {
		t.Fatalf("cmd_get_mirror_m2 not called")
	}
	if mock.Stats(cmd_get_fileinfomirror_m1) < 1 {
		t.Fatalf("cmd_get_fileinfomirror_m1 not called")
	}
	if mock.Stats(cmd_get_fileinfomirror_m2) < 1 {
		t.Fatalf("cmd_get_fileinfomirror_m2 not called")
	}

	if len(mirrors) != 2 {
		t.Fatalf("Invalid number of mirrors returned")
	}

	if int(mirrors[0].Distance) != int(876) {
		t.Fatalf("Distance between user and m1 is wrong, got %d, expected 876", int(mirrors[0].Distance))
	}

	if int(mirrors[1].Distance) != int(334) {
		t.Fatalf("Distance between user and m2 is wrong, got %d, expected 334", int(mirrors[1].Distance))
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:87,代码来源:cache_test.go


示例18: TestByRank_Less

func TestByRank_Less(t *testing.T) {
	rand.Seed(time.Now().UnixNano())

	/* */

	c := network.GeoIPRecord{}
	if c.IsValid() {
		t.Fatalf("GeoIPRecord is supposed to be invalid")
	}

	/* */

	// Generate two identical slices
	m1 := generateSimpleMirrorList(50)
	m2 := generateSimpleMirrorList(50)

	// Mirrors are indentical (besides name) so ByRank is expected
	// to randomize their order.
	sort.Sort(ByRank{m1, c})

	differences := 0
	for i, m := range m1 {
		if m.ID != m2[i].ID {
			differences++
		}
	}

	if differences == 0 {
		t.Fatalf("Result is supposed to be randomized")
	} else if differences < 10 {
		t.Fatalf("Too many similarities, something's wrong?")
	}

	// Sort again, just to be sure the result is different
	m3 := generateSimpleMirrorList(50)
	sort.Sort(ByRank{m3, c})

	differences = 0
	for i, m := range m3 {
		if m.ID != m1[i].ID {
			differences++
		}
	}

	if differences == 0 {
		t.Fatalf("Result is supposed to be different from previous run")
	} else if differences < 10 {
		t.Fatalf("Too many similarities, something's wrong?")
	}

	/* */

	c = network.GeoIPRecord{
		GeoIPRecord: &geoip.GeoIPRecord{
			CountryCode:   "FR",
			ContinentCode: "EU",
		},
		ASNum: 4444,
	}
	if !c.IsValid() {
		t.Fatalf("GeoIPRecord is supposed to be valid")
	}

	/* asnum */

	m := Mirrors{
		Mirror{
			ID:    "M0",
			Asnum: 6666,
		},
		Mirror{
			ID:    "M1",
			Asnum: 5555,
		},
		Mirror{
			ID:    "M2",
			Asnum: 4444,
		},
		Mirror{
			ID:    "M3",
			Asnum: 6666,
		},
	}

	sort.Sort(ByRank{m, c})

	if !matchingMirrorOrder(m, []string{"M2", "M0", "M1", "M3"}) {
		t.Fatalf("Order doesn't seem right: %s, expected M2, M0, M1, M3", formatMirrorOrder(m))
	}

	/* distance */

	m = Mirrors{
		Mirror{
			ID:       "M0",
			Distance: 1000.0,
		},
		Mirror{
			ID:       "M1",
			Distance: 999.0,
//.........这里部分代码省略.........
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:101,代码来源:mirrors_test.go


示例19: TestCache_GetFileInfo

func TestCache_GetFileInfo(t *testing.T) {
	mock, conn := PrepareRedisTest()
	conn.ConnectPubsub()

	c := NewCache(conn)

	testfile := filesystem.FileInfo{
		Path:    "/test/file.tgz",
		Size:    43000,
		ModTime: time.Now(),
		Sha1:    "3ce963aea2d6f23fe915063f8bba21888db0ddfa",
		Sha256:  "1c8e38c7e03e4d117eba4f82afaf6631a9b79f4c1e9dec144d4faf1d109aacda",
		Md5:     "2c98ec39f49da6ddd9cfa7b1d7342afe",
	}

	_, err := c.GetFileInfo(testfile.Path)
	if err == nil {
		t.Fatalf("Error expected, mock command not yet registered")
	}

	cmd_get_fileinfo := mock.Command("HMGET", "FILE_"+testfile.Path, "size", "modTime", "sha1", "sha256", "md5").Expect([]interface{}{
		[]byte(strconv.FormatInt(testfile.Size, 10)),
		[]byte(testfile.ModTime.String()),
		[]byte(testfile.Sha1),
		[]byte(testfile.Sha256),
		[]byte(testfile.Md5),
	})

	f, err := c.GetFileInfo(testfile.Path)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err.Error())
	}

	if mock.Stats(cmd_get_fileinfo) < 1 {
		t.Fatalf("HMGET not executed")
	}

	// Results are already checked by TestCache_fetchFileInfo
	// We only need to check one of them
	if f.ModTime != testfile.ModTime {
		t.Fatalf("One or more values do not match")
	}

	_, err = c.GetFileInfo(testfile.Path)
	if err == redis.ErrNil {
		t.Fatalf("Cache not used, request expected to be done once")
	} else if err != nil {
		t.Fatalf("Unexpected error: %s", err.Error())
	}
}
开发者ID:wsnipex,项目名称:mirrorbits,代码行数:50,代码来源:cache_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang color.Print函数代码示例发布时间:2022-05-28
下一篇:
Golang gompcreader.MinorPlanet类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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