Beispiel #1
0
func equals(tb testing.TB, exp, act interface{}) {
	if !reflect.DeepEqual(exp, act) {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
		tb.Fail()
	}
}
Beispiel #2
0
// ExpectNEQ fails the test and displays 'msg', if exp is equal to act.
func ExpectNEQ(tb testing.TB, exp, act interface{}, msg string) {
	if reflect.DeepEqual(exp, act) {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("%s:%d: %s\n\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, msg, exp, act)
		tb.Fail()
	}
}
Beispiel #3
0
// Expect fails the test and displays 'msg', if the condition is false.
func Expect(tb testing.TB, condition bool, msg string, v ...interface{}) {
	if !condition {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("%s:%d: "+msg+"\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
		tb.Fail()
	}
}
Beispiel #4
0
// ExpectOk fails the test and displays 'err', if an err is not nil. Returns true if err is nil, false otherwise.
func ExpectOk(tb testing.TB, err error) bool {
	if err != nil {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("%s:%d: unexpected error: %s\n\n", filepath.Base(file), line, err.Error())
		tb.Fail()
		return false
	}
	return true
}
Beispiel #5
0
func performChat(t testing.TB, conn *grpc.ClientConn) error {
	serverClient := pb.NewPeerClient(conn)
	stream, err := serverClient.Chat(context.Background())
	if err != nil {
		t.Logf("%v.performChat(_) = _, %v", serverClient, err)
		return err
	}
	defer stream.CloseSend()
	t.Log("Starting performChat")

	waitc := make(chan struct{})
	go func() {
		// Be sure to close the channel
		defer close(waitc)
		for {
			in, err := stream.Recv()
			if err == io.EOF {
				t.Logf("Received EOR, exiting chat")
				return
			}
			if err != nil {
				t.Errorf("stream closed with unexpected error: %s", err)
				return
			}
			if in.Type == pb.Message_DISC_HELLO {
				t.Logf("Received message: %s, sending %s", in.Type, pb.Message_DISC_GET_PEERS)
				stream.Send(&pb.Message{Type: pb.Message_DISC_GET_PEERS})
			} else if in.Type == pb.Message_DISC_PEERS {
				//stream.Send(&pb.DiscoveryMessage{Type: pb.DiscoveryMessage_PEERS})
				t.Logf("Received message: %s", in.Type)
				t.Logf("Closing stream and channel")
				return
			} else {
				t.Logf("Received message: %s", in.Type)

			}

		}
	}()
	select {
	case <-waitc:
		return nil
	case <-time.After(1 * time.Second):
		t.Fail()
		return fmt.Errorf("Timeout expired while performChat")
	}
}
Beispiel #6
0
func sendLargeMsg(t testing.TB) (*pb.Message, error) {
	vm, err := container.NewVM()
	if err != nil {
		t.Fail()
		t.Logf("Error getting VM: %s", err)
		return nil, err
	}

	inputbuf, err := vm.GetPeerPackageBytes()
	if err != nil {
		t.Fail()
		t.Logf("Error Getting Peer package bytes: %s", err)
		return nil, err
	}
	payload, err := ioutil.ReadAll(inputbuf)
	return &pb.Message{Type: pb.Message_DISC_NEWMSG, Payload: payload}, nil

}
func innerTest(client *FlumeClient, t testing.TB) {

	//header: {businessName=feed, type=list}.
	//body: 100311	list	{"view_self":0,"remoteid":"5445285","timestamp":1403512030,"flume_timestamp":"2014-06-23 16:27:10","business_type":"feed"}
	body := "{\"view_self\":0,\"remoteid\":\"5445285\",\"timestamp\":1403512030,\"flume_timestamp\":\"2014-06-23 16:27:10\",\"business_type\":\"feed\"}"

	var demo LogDemo
	err := json.Unmarshal([]byte(body), &demo)
	if nil != err {
		t.Fail()
		return
	}

	data, err := json.Marshal(demo)
	if nil != err {
		t.Fail()
		return
	}

	event := NewFlumeEvent("feed", "list", data)
	events := []*flume.ThriftFlumeEvent{event}
	for i := 0; i < 1; i++ {

		err := client.AppendBatch(events)
		err = client.Append(event)
		if nil != err {
			t.Log(err.Error())
			t.Fail()

		} else {
			t.Logf("%d, send succ ", i)
		}
	}
}
func innerTest(client *FlumeClient, t testing.TB) {

	//header: {businessName=feed, type=list}.
	//body: 100311	list	{"view_self":0,"remoteid":"5445285","timestamp":1403512030,"flume_timestamp":"2014-06-23 16:27:10","business_type":"feed"}
	body := "{\"view_self\":0,\"remoteid\":\"5445285\",\"timestamp\":1403512030,\"flume_timestamp\":\"2014-06-23 16:27:10\",\"business_type\":\"feed\"}"

	var demo LogDemo
	err := json.Unmarshal([]byte(body), &demo)
	if nil != err {
		t.Fail()
		return
	}

	data, err := json.Marshal(demo)
	if nil != err {
		t.Fail()
		return
	}

	header := make(map[string]string, 2)
	header["businessName"] = "feed"
	header["type"] = "list"

	for i := 0; i < 1; i++ {

		err := client.Append(header, data)
		if nil != err {
			t.Log(err.Error())
			t.Fail()

		} else {
			t.Logf("%d, send succ ", i)
		}
	}
}
Beispiel #9
0
func (e *callRecord) assert(t testing.TB, name string, params ...interface{}) {
	if name != e.name {
		t.Logf("Expected call to %s%s", e.name, paramsToString(e.params))
		t.Logf(" got call to %s%s", name, paramsToString(params))
		showStack(t)
		t.Fail()
		return
	}
	if len(params) != len(e.params) {
		t.Logf("Call to (%s) unexpected parameters", name)
		t.Logf(" expected %s", paramsToString(e.params))
		t.Logf("      got %s", paramsToString(params))
		showStack(t)
		t.FailNow()
		return
	}
	for i, ap := range params {
		ep := e.params[i]

		if ap == nil && ep == nil {
			continue
		}

		switch ep := ep.(type) {
		case func(actual interface{}):
			ep(ap)
		default:
			if !reflect.DeepEqual(ap, ep) {
				t.Logf("Call to %s parameter %d unexpected", name, i)
				t.Logf("  expected %#v (%T)", ep, ep)
				t.Logf("       got %#v (%T)", ap, ap)
				showStack(t)
				t.Fail()
			}
		}
	}
}
Beispiel #10
0
func innerApsnHttpServerSend(t testing.TB) {

	// fmt.Println("innerApsnHttpServerSend is Starting")

	data := make(url.Values)
	data.Set("pt", NOTIFY_ENHANCED_FORMAT)
	data.Set("token", apnsToken)
	data.Set("sound", "ms.caf")
	data.Set("badge", "10")
	data.Set("body", "HTTP APNS SERVER TEST! ")
	data.Set("extArgs", "{\"name\":\"blackbeans\"}")

	//然后发起调用
	resp, err := http.PostForm(PROXY_URL+"/apns/push", data)
	if nil != err {
		t.Logf("HTTP POST PUSH FAIL!%s\n", err)
		t.Fail()
		return
	}

	var body []byte
	body, err = ioutil.ReadAll(resp.Body)
	if nil != err {
		// fmt.Printf("HTTP READ RESPONSE FAIL !|%s", err)
		t.Fail()
		return
	}

	defer resp.Body.Close()

	var response response
	err = json.Unmarshal(body, &response)
	if nil != err {
		// fmt.Printf("innerApsnHttpServerSend|HTTP Unmarshal RESPONSE FAIL !|%s\n", body)
		t.Fail()
		return
	}
	// fmt.Printf("--------------respose:%s\n", response)

	if response.Status != RESP_STATUS_SUCC {
		t.Fail()
		return
	}
}
Beispiel #11
0
func testF(tb testing.TB, msg string, res bool) {
	if !res {
		fmt.Printf("exp: %s\n", msg)
		tb.Fail()
	}
}