本文整理汇总了Golang中github.com/wsnipex/mirrorbits/testing.T类的典型用法代码示例。如果您正苦于以下问题:Golang T类的具体用法?Golang T怎么用?Golang T使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了T类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
}
示例2: TestMarkMirrorDown
func TestMarkMirrorDown(t *testing.T) {
_, conn := PrepareRedisTest()
if err := MarkMirrorDown(conn, "m1", "test1"); err == nil {
t.Fatalf("Error expected but nil returned")
}
}
示例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))
}
}
示例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())
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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?")
}
}
示例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)
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}