-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb48da9
commit 253d7bf
Showing
5 changed files
with
137 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package lime | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/goleak" | ||
"log" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestClient_NewClient_Message(t *testing.T) { | ||
// Arrange | ||
defer goleak.VerifyNone(t) | ||
ctx, cancel := context.WithTimeout(context.Background(), 250*time.Millisecond) | ||
defer cancel() | ||
addr1 := InProcessAddr("localhost") | ||
msgChan := make(chan *Message, 1) | ||
server := NewServerBuilder(). | ||
ListenInProcess(addr1). | ||
MessagesHandlerFunc( | ||
func(ctx context.Context, msg *Message, s Sender) error { | ||
msgChan <- msg | ||
return nil | ||
}). | ||
Build() | ||
defer silentClose(server) | ||
go func() { | ||
if err := server.ListenAndServe(); err != nil && !errors.Is(err, ErrServerClosed) { | ||
log.Println(err) | ||
} | ||
}() | ||
config := NewClientConfig() | ||
config.NewTransport = func(ctx context.Context) (Transport, error) { | ||
return DialInProcess(addr1, 1) | ||
} | ||
mux := &EnvelopeMux{} | ||
client := NewClient(config, mux) | ||
msg := createMessage() | ||
|
||
// Act | ||
err := client.SendMessage(ctx, msg) | ||
|
||
// Assert | ||
assert.NoError(t, err) | ||
rcvMsg := <-msgChan | ||
assert.Equal(t, msg, rcvMsg) | ||
err = client.Close() | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters