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


Golang test-helpers.Ok函數代碼示例

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


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

示例1: TestFetchHypervisors

func TestFetchHypervisors(t *testing.T) {

	// Setup
	f := NewFetcher("http://127.0.0.1:4001")
	defer testhelper.Cleanup(f.etcdClient)

	// Create supporting objects
	n, err := testhelper.NewNetwork(f.context)
	h.Ok(t, err)
	s, err := testhelper.NewSubnet(f.context, "10.10.10.0/24", net.IPv4(10, 10, 10, 1), net.IPv4(10, 10, 10, 10), net.IPv4(10, 10, 10, 250), n)
	h.Ok(t, err)

	// Create two hypervisors
	h1, err := testhelper.NewHypervisor(f.context, "de:ad:be:ef:7f:21", net.IPv4(192, 168, 100, 200), net.IPv4(192, 168, 100, 1), net.IPv4(255, 255, 255, 0), "br0", s)
	h.Ok(t, err)
	h2, err := testhelper.NewHypervisor(f.context, "de:ad:be:ef:7f:23", net.IPv4(192, 168, 100, 203), net.IPv4(192, 168, 100, 1), net.IPv4(255, 255, 255, 0), "br0", s)
	h.Ok(t, err)

	// Fetch and make sure they're present
	hvs, err := f.Hypervisors()
	h.Ok(t, err)
	if _, ok := hvs[h1.ID]; !ok {
		t.Error("Hypervisor #1 is missing from list")
	}
	h.Equals(t, hvs[h1.ID].MAC.String(), "de:ad:be:ef:7f:21")
	if _, ok := hvs[h2.ID]; !ok {
		t.Error("Hypervisor #2 is missing from list")
	}
	h.Equals(t, hvs[h2.ID].MAC.String(), "de:ad:be:ef:7f:23")

}
開發者ID:joshie,項目名稱:lochness,代碼行數:31,代碼來源:fetcher_test.go

示例2: TestFetchSubnets

func TestFetchSubnets(t *testing.T) {

	// Setup
	f := NewFetcher("http://127.0.0.1:4001")
	defer testhelper.Cleanup(f.etcdClient)

	// Create supporting object
	n, err := testhelper.NewNetwork(f.context)
	h.Ok(t, err)

	// Create two subnets
	s1, err := testhelper.NewSubnet(f.context, "10.10.10.0/24", net.IPv4(10, 10, 10, 1), net.IPv4(10, 10, 10, 10), net.IPv4(10, 10, 10, 250), n)
	h.Ok(t, err)
	s2, err := testhelper.NewSubnet(f.context, "12.12.12.0/24", net.IPv4(12, 12, 12, 1), net.IPv4(12, 12, 12, 12), net.IPv4(12, 12, 12, 250), n)
	h.Ok(t, err)

	// Fetch and make sure they're present
	ss, err := f.Subnets()
	h.Ok(t, err)
	if _, ok := ss[s1.ID]; !ok {
		t.Error("Subnet #1 is missing from list")
	}
	h.Equals(t, ss[s1.ID].CIDR.String(), "10.10.10.0/24")
	if _, ok := ss[s2.ID]; !ok {
		t.Error("Subnet #2 is missing from list")
	}
	h.Equals(t, ss[s2.ID].CIDR.String(), "12.12.12.0/24")

}
開發者ID:joshie,項目名稱:lochness,代碼行數:29,代碼來源:fetcher_test.go

示例3: TestNetworkAddSubnet

func TestNetworkAddSubnet(t *testing.T) {
	defer contextCleanup(t)
	n := newNetwork(t)
	h.Equals(t, 36, len(n.ID))
	err := n.Save()
	h.Ok(t, err)

	s := newSubnet(t)

	err = n.AddSubnet(s)
	h.Ok(t, err)

	h.Equals(t, 1, len(n.Subnets()))
}
開發者ID:joshie,項目名稱:lochness,代碼行數:14,代碼來源:network_test.go

示例4: TestFWGroupJson

func TestFWGroupJson(t *testing.T) {
	data := `{"id": "EF8D7367-F14F-49C9-B960-2625947CA929", "rules": [ {"source": "192.168.1.0/24", "portStart": 80, "portEnd": 80, "protocol": "tcp", "action": "allow"} ] }`

	f := lochness.FWGroup{}
	err := json.Unmarshal([]byte(data), &f)
	h.Ok(t, err)
	h.Equals(t, "EF8D7367-F14F-49C9-B960-2625947CA929", f.ID)
	h.Equals(t, 1, len(f.Rules))
	h.Equals(t, "192.168.1.0", f.Rules[0].Source.IP.String())

	b, err := json.Marshal(&f)
	h.Ok(t, err)

	h.Assert(t, strings.Contains(string(b), "192.168.1.0/24"), "incorrect source information")
}
開發者ID:joshie,項目名稱:lochness,代碼行數:15,代碼來源:fwgroup_test.go

示例5: TestNewNetwork

func TestNewNetwork(t *testing.T) {
	defer contextCleanup(t)
	n := newNetwork(t)
	h.Equals(t, 36, len(n.ID))
	err := n.Save()
	h.Ok(t, err)
}
開發者ID:joshie,項目名稱:lochness,代碼行數:7,代碼來源:network_test.go

示例6: newSubnet

func newSubnet(t *testing.T) *lochness.Subnet {
	c := newContext(t)
	s := c.NewSubnet()

	var err error
	_, s.CIDR, err = net.ParseCIDR("10.10.10.0/24")
	h.Ok(t, err)

	s.StartRange = net.IPv4(10, 10, 10, 10)
	s.EndRange = net.IPv4(10, 10, 10, 100)

	err = s.Save()
	h.Ok(t, err)

	return s
}
開發者ID:joshie,項目名稱:lochness,代碼行數:16,代碼來源:subnet_test.go

示例7: TestSubnetSave

func TestSubnetSave(t *testing.T) {
	s := newSubnet(t)
	defer removeSubnet(t, s)

	s.Metadata["foo"] = "bar"
	err := s.Save()
	h.Ok(t, err)
}
開發者ID:joshie,項目名稱:lochness,代碼行數:8,代碼來源:subnet_test.go

示例8: TestHypervisorSetConfig

func TestHypervisorSetConfig(t *testing.T) {
	hv := newHypervisor(t)
	defer contextCleanup(t)

	h.Ok(t, hv.SetConfig("foo", "bar"))

	h.Equals(t, "bar", hv.Config["foo"])

	h.Ok(t, hv.Refresh())

	h.Equals(t, "bar", hv.Config["foo"])

	h.Ok(t, hv.SetConfig("foo", ""))

	_, ok := hv.Config["foo"]
	h.Equals(t, ok, false)
}
開發者ID:joshie,項目名稱:lochness,代碼行數:17,代碼來源:hypervisor_test.go

示例9: TestHypervisorDestroy

func TestHypervisorDestroy(t *testing.T) {
	defer contextCleanup(t)
	hv := newHypervisor(t)

	err := hv.Destroy()
	h.Ok(t, err)
	// need a test with a guest
}
開發者ID:joshie,項目名稱:lochness,代碼行數:8,代碼來源:hypervisor_test.go

示例10: newHypervisor

func newHypervisor(t *testing.T) *lochness.Hypervisor {
	c := newContext(t)
	hv := c.NewHypervisor()

	err := hv.Save()
	h.Ok(t, err)

	return hv
}
開發者ID:joshie,項目名稱:lochness,代碼行數:9,代碼來源:hypervisor_test.go

示例11: TestHypervisor

func TestHypervisor(t *testing.T) {
	c := newContext(t)
	defer contextCleanup(t)
	hv := newHypervisor(t)
	id := hv.ID
	hv, err := c.Hypervisor(id)
	h.Ok(t, err)
	h.Equals(t, id, hv.ID)
}
開發者ID:joshie,項目名稱:lochness,代碼行數:9,代碼來源:hypervisor_test.go

示例12: TestSubnetReleaseAddress

func TestSubnetReleaseAddress(t *testing.T) {
	s := newSubnet(t)
	defer removeSubnet(t, s)

	ip := reserveAddress(t, s)
	err := s.ReleaseAddress(ip)
	h.Ok(t, err)

	h.Equals(t, 91, len(s.AvailibleAddresses()))

	// make sure change persists
	err = s.Refresh()
	h.Ok(t, err)

	h.Equals(t, 91, len(s.AvailibleAddresses()))

	h.Equals(t, 0, len(s.Addresses()))

}
開發者ID:joshie,項目名稱:lochness,代碼行數:19,代碼來源:subnet_test.go

示例13: reserveAddress

func reserveAddress(t *testing.T, s *lochness.Subnet) net.IP {
	ip, err := s.ReserveAddress("fake")
	h.Ok(t, err)

	h.Assert(t, strings.Contains(ip.String(), "10.10.10."), "unexpected ip address")

	h.Equals(t, 90, len(s.AvailibleAddresses()))

	h.Equals(t, 1, len(s.Addresses()))

	// make sure change persists
	err = s.Refresh()
	h.Ok(t, err)

	h.Equals(t, 90, len(s.AvailibleAddresses()))

	return ip

}
開發者ID:joshie,項目名稱:lochness,代碼行數:19,代碼來源:subnet_test.go

示例14: TestGetHypervisorID

func TestGetHypervisorID(t *testing.T) {
	uuid := "d3cac004-4d89-4f26-9776-97df74a41417"
	id, err := lochness.SetHypervisorID(uuid)
	h.Ok(t, err)
	h.Equals(t, uuid, id)

	id = lochness.GetHypervisorID()
	h.Equals(t, uuid, id)

}
開發者ID:joshie,項目名稱:lochness,代碼行數:10,代碼來源:hypervisor_test.go

示例15: contextCleanup

func contextCleanup(t *testing.T) {
	e := etcd.NewClient([]string{"http://127.0.0.1:4001"})
	if !e.SyncCluster() {
		t.Fatal("cannot sync cluster. make sure etcd is running at http://127.0.0.1:4001")
	}

	_, err := e.Delete("lochness", true)
	if !lochness.IsKeyNotFound(err) {
		h.Ok(t, err)
	}
}
開發者ID:joshie,項目名稱:lochness,代碼行數:11,代碼來源:context_test.go


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