func TestGenerateHandshakeId(t *testing.T) {
	clientDone := make(chan struct{})
	serverDone := make(chan struct{})
	var uuidsArray = [5]string{}
	for i := 1; i < len(uuidsArray); i++ {
		id, _ := uuid.NewRandom()
		uuidsArray[i] = id.String()
	}
	var uchan = make(chan string, len(uuidsArray))
	for _, elt := range uuidsArray {
		uchan <- elt
	}
	h := func(t *testing.T, sc *ServerConn) {
		checkOpenStreamHandshakeID(t, sc, <-uchan)
		readHandshakeComponent(t, sc.decoder)
		sc.connection.Write([]byte("<handshake/>"))  
		serverDone <- struct{}{}
	}
	testComponentAddess := fmt.Sprintf("%s:%d", testComponentDomain, testHandshakePort)
	mock := ServerMock{}
	mock.Start(t, testComponentAddess, h)
	opts := ComponentOptions{
		TransportConfiguration: TransportConfiguration{
			Address: testComponentAddess,
			Domain:  "localhost",
		},
		Domain:   testComponentDomain,
		Secret:   "mypass",
		Name:     "Test Component",
		Category: "gateway",
		Type:     "service",
	}
	router := NewRouter()
	c, err := NewComponent(opts, router, componentDefaultErrorHandler)
	if err != nil {
		t.Errorf("%+v", err)
	}
	c.transport, err = NewComponentTransport(c.ComponentOptions.TransportConfiguration)
	if err != nil {
		t.Errorf("%+v", err)
	}
	go func() {
		m := make(map[string]bool)
		for range uuidsArray {
			idChan := make(chan string)
			go func() {
				streamId, err := c.transport.Connect()
				if err != nil {
					t.Fatalf("failed to mock component connection to get a handshake: %s", err)
				}
				idChan <- streamId
			}()
			var streamId string
			select {
			case streamId = <-idChan:
			case <-time.After(defaultTimeout):
				t.Fatalf("test timed out")
			}
			hs := stanza.Handshake{
				Value: c.handshake(streamId),
			}
			m[hs.Value] = true
			hsRaw, err := xml.Marshal(hs)
			if err != nil {
				t.Fatalf("could not marshal handshake: %s", err)
			}
			c.SendRaw(string(hsRaw))
			waitForEntity(t, serverDone)
			c.transport.Close()
		}
		if len(uuidsArray) != len(m) {
			t.Errorf("Handshake does not produce a unique id. Expected: %d unique ids, got: %d", len(uuidsArray), len(m))
		}
		clientDone <- struct{}{}
	}()
	waitForEntity(t, clientDone)
	mock.Stop()
}
Tests connection process with a handshake exchange
Tests multiple session IDs. All serverConnections should generate a unique stream ID
package xmpp
import (
	"context"
	"encoding/xml"
	"errors"
	"fmt"
	"strings"
	"testing"
	"time"
	"github.com/google/uuid"
	"gosrc.io/xmpp/stanza"
)
const (
	defaultChannelTimeout = 5 * time.Second
)
func TestHandshake(t *testing.T) {
	opts := ComponentOptions{
		Domain: "test.localhost",
		Secret: "mypass",
	}
	c := Component{ComponentOptions: opts}
	streamID := "1263952298440005243"
	expected := "c77e2ef0109fbbc5161e83b51629cd1353495332"
	result := c.handshake(streamID)
	if result != expected {
		t.Errorf("incorrect handshake calculation '%s' != '%s'", result, expected)
	}
}