added a few tests for inmemoryconnection.

This commit is contained in:
Erik Brakkee 2024-08-21 16:58:15 +02:00
parent ab5fdf4f7e
commit e0b6e644b6
4 changed files with 49 additions and 2 deletions

View File

@ -49,7 +49,7 @@ func (s *GOBChannelTestSuite) SetupTest() {
func (s *GOBChannelTestSuite) TearDownTest() { func (s *GOBChannelTestSuite) TearDownTest() {
} }
func TestNewGOBChannel(t *testing.T) { func TestNewGOBChannelSuite(t *testing.T) {
suite.Run(t, &GOBChannelTestSuite{}) suite.Run(t, &GOBChannelTestSuite{})
} }

View File

@ -23,7 +23,7 @@ func (s *LinkedMapTestSuite) SetupTest() {
func (s *LinkedMapTestSuite) TearDownTest() { func (s *LinkedMapTestSuite) TearDownTest() {
} }
func TestLinkedMap(t *testing.T) { func TestLinkedMapSuite(t *testing.T) {
suite.Run(t, &LinkedMapTestSuite{}) suite.Run(t, &LinkedMapTestSuite{})
} }

View File

@ -3,6 +3,7 @@ package testsupport
import ( import (
"context" "context"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"io"
"net/http" "net/http"
"testing" "testing"
"time" "time"
@ -43,3 +44,41 @@ func (s *InMemoryTestSuite) SetupTest() {
func (s *InMemoryTestSuite) TearDownTest() { func (s *InMemoryTestSuite) TearDownTest() {
s.cancelFunc() s.cancelFunc()
} }
// All test cases can be performed with Front() and Back reversed since they are just two sides of the same Pipe.
func (s *InMemoryTestSuite) SendReceive(a io.ReadWriteCloser, b io.ReadWriteCloser) {
data := "hello"
n, err := a.Write([]byte(data))
s.Nil(err)
s.Equal(len(data), n)
buf := make([]byte, len(data)*2)
n, err = b.Read(buf)
s.Nil(err)
s.Equal([]byte(data), buf[:n])
}
func (s *InMemoryTestSuite) Test_SendReceive1() {
s.SendReceive(s.pipe.Front(), s.pipe.Back())
}
func (s *InMemoryTestSuite) Test_SendReceive2() {
s.SendReceive(s.pipe.Back(), s.pipe.Front())
}
func (s *InMemoryTestSuite) closeLeadsToEofOnRead(a io.ReadWriteCloser, b io.ReadWriteCloser) {
a.Close()
buf := make([]byte, 100)
n, err := b.Read(buf)
s.Equal(io.EOF, err)
s.Equal(0, n)
}
func (s *InMemoryTestSuite) Test_CloseLeadsToEofOnRead1() {
s.closeLeadsToEofOnRead(s.pipe.Front(), s.pipe.Back())
}
func (s *InMemoryTestSuite) Test_CloseLeadsToEofOnRead2() {
s.closeLeadsToEofOnRead(s.pipe.Back(), s.pipe.Front())
}

8
teststats.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
testout="$( make test )"
echo "Total: $( echo "$testout" | grep -v 'Suite[^/]' | grep -cE '^ *--- (PASS|FAIL)' )"
echo "Pass: $( echo "$testout" | grep -v 'Suite[^/]' | grep -cE '^ *--- PASS' )"
echo "Fail: $( echo "$testout" | grep -v 'Suite[^/]' | grep -cE '^ *--- FAIL' )"