func TestRunnerHandleLobbyMessagePlayerRemove(t *testing.T) {
	c1 := make(chan message.Message)
	c2 := make(chan message.Message, 1)
	c3 := make(chan message.Message)
	// player delete is sent from the lobby when the player is actually deleted
	playerSockets := map[player.Name]map[message.Addr]chan<- message.Message{
		"fred": {
			"addr1": c1,
			"addr3": c3,
		},
		"barney": {
			"addr2": c2,
		},
	}
	playerGames := map[player.Name]map[game.ID]message.Addr{
		"fred": {
			1: "addr1",
		},
		"barney": {
			1: "addr2",
		},
	}
	r := Runner{
		playerSockets: playerSockets,
		playerGames:   playerGames,
	}
	sm := message.Socket{
		Type:       message.PlayerRemove,
		PlayerName: "fred",
	}
	socketOut := make(chan message.Message)
	lobbyIn := make(chan message.Message)
	wantPlayerSockets := map[player.Name]map[message.Addr]chan<- message.Message{
		"barney": {
			"addr2": c2,
		},
	}
	wantPlayerGames := map[player.Name]map[game.ID]message.Addr{
		"barney": {
			1: "addr2",
		},
	}
	ctx := context.Background()
	var wg sync.WaitGroup
	r.handleLobbyModifyRequest(ctx, &wg, sm, socketOut, lobbyIn)
	switch {
	case !reflect.DeepEqual(wantPlayerSockets, r.playerSockets):
		t.Errorf("player sockets not equal:\nwanted: %v\ngot:    %v", wantPlayerSockets, r.playerSockets)
	case !reflect.DeepEqual(wantPlayerGames, r.playerGames):
		t.Errorf("player games not equal:\nwanted: %v\ngot:    %v", wantPlayerGames, r.playerGames)
	default:
		// ensure the sockets are closed or left open
		<-c1
		<-c3
		c2 <- message.Message{Info: "ok"}
		m := <-c2
		if m.Info != "ok" {
			t.Errorf("wanted c2 to be left open")
		}
	}
}
// TestRunnerHandleLobbyMessagePlayerRemove verifies the sockets are closed.
TestRunnerHandleLobbyMessagePlayerRemove verifies the sockets are closed.
// TestRunnerHandleLobbyMessagePlayerRemove verifies the sockets are closed .
func TestRunnerHandleLobbyMessagePlayerRemove(t *testing.T) {
	c1 := make(chan message.Message)
	c2 := make(chan message.Message, 1)
	c3 := make(chan message.Message)
	playerSockets := map[player.Name]map[message.Addr]chan<- message.Message{
		"fred": {
			"addr1": c1,
			"addr3": c3,
		},
		"barney": {
			"addr2": c2,
		},
	}
	playerGames := map[player.Name]map[game.ID]message.Addr{
		"fred": {
			1: "addr1",
		},
		"barney": {
			1: "addr2",
		},
	}
	r := Runner{
		playerSockets: playerSockets,
		playerGames:   playerGames,
	}
	sm := message.Socket{
		Type:       message.PlayerRemove,
		PlayerName: "fred",
	}
	socketOut := make(chan message.Message)
	lobbyIn := make(chan message.Message)
	wantPlayerSockets := map[player.Name]map[message.Addr]chan<- message.Message{
		"barney": {
			"addr2": c2,
		},
	}
	wantPlayerGames := map[player.Name]map[game.ID]message.Addr{
		"barney": {
			1: "addr2",
		},
	}
	ctx := context.Background()
	var wg sync.WaitGroup
	r.handleLobbyModifyRequest(ctx, &wg, sm, socketOut, lobbyIn)
	switch {
	case !reflect.DeepEqual(wantPlayerSockets, r.playerSockets):
		t.Errorf("player sockets not equal:\nwanted: %v\ngot:    %v", wantPlayerSockets, r.playerSockets)
	case !reflect.DeepEqual(wantPlayerGames, r.playerGames):
		t.Errorf("player games not equal:\nwanted: %v\ngot:    %v", wantPlayerGames, r.playerGames)
	default:
		<-c1
		<-c3
		c2 <- message.Message{Info: "ok"}
		m := <-c2
		if m.Info != "ok" {
			t.Errorf("wanted c2 to be left open")
		}
	}
}
func TestRunnerHandleLobbyMessagePlayerRemove ( t * testing . T ) { c1 := make ( chan message . Message ) c2 := make ( chan message . Message , 1 ) c3 := make ( chan message . Message ) playerSockets := map [ player . Name ] map [ message . Addr ] chan <- message . Message { " " : { " " : c1 , " " : c3 , } , " " : { " " : c2 , } , } playerGames := map [ player . Name ] map [ game . ID ] message . Addr { " " : { 1 : " " , } , " " : { 1 : " " , } , } r := Runner { playerSockets : playerSockets , playerGames : playerGames , } sm := message . Socket { Type : message . PlayerRemove , PlayerName : " " , } socketOut := make ( chan message . Message ) lobbyIn := make ( chan message . Message ) wantPlayerSockets := map [ player . Name ] map [ message . Addr ] chan <- message . Message { " " : { " " : c2 , } , } wantPlayerGames := map [ player . Name ] map [ game . ID ] message . Addr { " " : { 1 : " " , } , } ctx := context . Background ( ) var wg sync . WaitGroup r . handleLobbyModifyRequest ( ctx , & wg , sm , socketOut , lobbyIn ) switch { case ! reflect . DeepEqual ( wantPlayerSockets , r . playerSockets ) : t . Errorf ( " \n \n " , wantPlayerSockets , r . playerSockets ) case ! reflect . DeepEqual ( wantPlayerGames , r . playerGames ) : t . Errorf ( " \n \n " , wantPlayerGames , r . playerGames ) default : <- c1 <- c3 c2 <- message . Message { Info : " " } m := <- c2 if m . Info != " " { t . Errorf ( " " ) } } }
TestRunnerHandleLobbyMessagePlayerRemove verifies the sockets are closed.
TestRunnerHandleLobbyMessagePlayerRemove verifies the sockets are closed .
// player delete is sent from the lobby when the player is actually deleted // ensure the sockets are closed or left open