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
			}
		})
	}
}
Example #2
0
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())
	})
}