// ParseSubscribeResponseAndCallUnsubscribe will parse the response on the go channel.
// It will check the subscribe connection status and when connected
// it will initiate the unsubscribe request.
func ParseSubscribeResponseAndCallUnsubscribe(pubnubInstance *pubnubMessaging.Pubnub, returnChannel chan []byte, t *testing.T, channel string, message string) {
	for {
		value, ok := <-returnChannel
		if !ok {
			break
		}
		if string(value) != "[]" {
			response := fmt.Sprintf("%s", value)

			message = "'" + channel + "' " + message
			messageAbort := "'" + channel + "' aborted"
			if strings.Contains(response, message) {
				returnUnsubscribeChannel := make(chan []byte)
				go pubnubInstance.Unsubscribe(channel, returnUnsubscribeChannel)
				ParseUnsubscribeResponse(returnUnsubscribeChannel, t, channel, "unsubscribed")
				break
			} else if strings.Contains(response, messageAbort) {
				t.Error("Test unsubscribed: failed.")
				break
			} else {
				t.Error("Test unsubscribed: failed.")
				break
			}
		}
	}
}