当前位置: 首页>>代码示例>>Golang>>正文


Golang T.Close方法代码示例

本文整理汇总了Golang中testing.T.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Close方法的具体用法?Golang T.Close怎么用?Golang T.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.T的用法示例。


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

示例1: TestRedisHandlerFailed

func TestRedisHandlerFailed(t *testing.T) {

	listener, e := net.Listen("tcp", ":0")
	if nil != e {
		t.Error(e)
		return
	}

	old := *redisAddress

	ss := strings.Split(listener.Addr().String(), ":")

	*redisAddress = "127.0.0.1:" + ss[len(ss)-1]

	defer func() {
		*redisAddress = old
		listener.Close()
	}()

	go func() {
		for {
			t, e := listener.Accept()
			if nil != e {
				return
			}

			t.Close()
		}
	}()

	for _, test := range []map[string]interface{}{
		{"command": "SET", "arg0": "a2", "arg1": "1224"},

		{"commands": []interface{}{[]interface{}{"SET", "a1", "1223"},
			[]interface{}{"SET", "a2", "1224"},
			[]interface{}{"SET", "a3", "1225"},
			[]interface{}{"SET", "a4", "1226"},
			[]interface{}{"SET", "a5", "1227"}}}} {

		redisTest(t, func(client *redis_gateway, c redis.Conn) {
			handler, e := newRedisHandler(map[string]interface{}{"redis": client}, test)
			if nil != e {
				t.Error(e)
				return
			}

			e = handler.Perform()
			if nil == e {
				t.Error("excepted error is not nil, but actual is nil")
				return
			}
		})
	}
}
开发者ID:runner-mei,项目名称:delayed_job,代码行数:54,代码来源:redis_handler_test.go

示例2: TestName

func TestName(t *testing.T) {

	Convey("Should kill them one.", t, func() {
		hits := NewTargets()
		hits.Add(NewWorker())
		hits.Add(NewWorker())
		hits.Add(NewWorker())
		hits.Add(NewWorker())

		So(len(hits), ShouldEqual, 4)
		err := hits.Close()
		So(err, ShouldBeNil)
	})

	Convey("New kill channels should have a length of 0.", t, func() {
		k := NewKillChannel()
		So(len(k), ShouldEqual, 0)
	})

	Convey("Should kill them one.", t, func() {
		hits := NewTargets()
		t := &Worker{}
		hits.Add(t)

		So(len(hits), ShouldEqual, 1)

		err := hits.Close()
		So(err, ShouldBeNil)
	})

	Convey("New Targets collection should have len of zero", t, func() {
		t := NewTargets()
		w := NewWorker()
		t.Add(w)

		v, ok := t[w.Name()]

		So(len(t), ShouldEqual, 1)
		So(v, ShouldNotBeNil)
		So(ok, ShouldBeTrue)
	})

	Convey("New Targets collection should have len of zero", t, func() {
		t := NewTargets()
		So(len(t), ShouldEqual, 0)
	})

	Convey("New Target via literals", t, func() {
		t := NewTargets()
		t.AddTarget(&Unnamed{})
		So(len(t), ShouldEqual, 1)
		t.Close()
	})

	Convey("New Target or panic should be fine if no error", t, func() {
		t := NewTargets()
		t.AddOrPanic(NewService())
		So(len(t), ShouldEqual, 1)
		t.Close()
	})

	Convey("Should panic when adding a service that failed to instantiate without error", t, func() {
		defer func() {
			panicky := recover()
			err, ok := panicky.(error)
			So(ok, ShouldBeTrue)
			So(err, ShouldNotBeNil)
		}()
		NewTargets().AddOrPanic(NewServiceWithError())
	})
}
开发者ID:lcaballero,项目名称:hitman,代码行数:71,代码来源:hitman_test.go


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