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

Golang test-helpers.Ok函数代码示例

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

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



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


示例16: TestVerifyOnHV

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

	// failing test
	uuid := "d3cac004-4d89-4f26-9776-97df74a41417"
	id, err := lochness.SetHypervisorID(uuid)
	h.Ok(t, err)
	h.Equals(t, uuid, id)

	err = hv.VerifyOnHV()
	h.Assert(t, err != nil, "should have got an error")

	// passing
	id, err = lochness.SetHypervisorID(hv.ID)
	h.Ok(t, err)
	h.Equals(t, hv.ID, id)

	err = hv.VerifyOnHV()
	h.Ok(t, err)
}
开发者ID:joshie,项目名称:lochness,代码行数:21,代码来源:hypervisor_test.go


示例17: TestIntegrateSubnetResponses

func TestIntegrateSubnetResponses(t *testing.T) {

	// Setup
	f := NewFetcher("http://127.0.0.1:4001")
	defer testhelper.Cleanup(f.etcdClient)
	_, err := f.Subnets()
	h.Ok(t, err)

	// Create-subnet integration
	s := f.context.NewSubnet()
	cidr := "77.77.77.0/24"
	_, s.CIDR, err = net.ParseCIDR(cidr)
	if err != nil {
		t.Error("Could not parse CIDR '" + cidr + "': " + err.Error())
	}
	sj, err := json.Marshal(s)
	h.Ok(t, err)
	key := filepath.Join(lochness.SubnetPath, s.ID, "metadata")
	resp, err := f.etcdClient.Create(key, string(sj), 0)
	h.Ok(t, err)
	refresh, err := f.IntegrateResponse(resp)
	h.Ok(t, err)
	h.Equals(t, refresh, true)
	h.Ok(t, err)
	ss, err := f.Subnets()
	h.Ok(t, err)
	if _, ok := ss[s.ID]; !ok {
		t.Error("Newly integrated subnet is missing from list")
	}
	h.Equals(t, ss[s.ID].CIDR.String(), cidr)

	// Delete-subnet integration
	resp, err = f.etcdClient.Delete(filepath.Join(lochness.SubnetPath, s.ID, "metadata"), false)
	h.Ok(t, err)
	refresh, err = f.IntegrateResponse(resp)
	h.Ok(t, err)
	h.Equals(t, refresh, true)
	ss, err = f.Subnets()
	h.Ok(t, err)
	if _, ok := ss[s.ID]; ok {
		t.Error("Newly deleted subnet is present in list")
	}
}
开发者ID:joshie,项目名称:lochness,代码行数:43,代码来源:fetcher_test.go


示例18: TestFirstHypervisor

func TestFirstHypervisor(t *testing.T) {
	c := newContext(t)
	newHypervisor(t)
	newHypervisor(t)
	hv := newHypervisor(t)
	defer contextCleanup(t)

	found, err := c.FirstHypervisor(func(h *lochness.Hypervisor) bool {
		return h.ID == "foo"
	})

	h.Ok(t, err)

	h.Assert(t, found == nil, "unexpected value")

	found, err = c.FirstHypervisor(func(h *lochness.Hypervisor) bool {
		return h.ID == hv.ID
	})

	h.Ok(t, err)

	h.Assert(t, found != nil, "unexpected nil")

}
开发者ID:joshie,项目名称:lochness,代码行数:24,代码来源:hypervisor_test.go


示例19: TestSetHypervisorID

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

	id, err = lochness.SetHypervisorID("foo")
	h.Assert(t, err != nil, "should have got an error")
	h.Equals(t, "", id)

	// set with ENV
	uuid = "3e0f2128-0342-49f6-8e5f-ecd401bae99e"
	if err := os.Setenv("HYPERVISOR_ID", uuid); err != nil {
		log.WithFields(log.Fields{
			"error": err,
			"uuid":  uuid,
		}).Error("failed to set HYPERVISOR_ID env variable")
	}
	id, err = lochness.SetHypervisorID("")
	h.Ok(t, err)
	h.Equals(t, uuid, id)

}
开发者ID:joshie,项目名称:lochness,代码行数:24,代码来源:hypervisor_test.go


示例20: TestHandlerFail

func TestHandlerFail(t *testing.T) {
	handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.WriteHeader(200)
		fmt.Fprint(w, "Hello World\n")
	})

	wl, err := whitelist.New([]string{"8.8.0.0/16"})
	h.Ok(t, err)

	request := newRequest("GET", "/foo", "9.9.9.9:9876")
	recorder := httptest.NewRecorder()
	wlHandler := wl.Handler(handler)

	wlHandler.ServeHTTP(recorder, request)

	h.Equals(t, 403, recorder.Code)
}
开发者ID:bakins,项目名称:go-http-whitelist,代码行数:17,代码来源:whitelist_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang codec.CheckHeader函数代码示例发布时间:2022-05-24
下一篇:
Golang test-helpers.Equals函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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