elbot/sending_test.go
Mihai Moldovanu bbf26c3987
All checks were successful
continuous-integration/drone/pr Build is passing
fix message
2022-04-17 11:48:42 +03:00

51 lines
1.1 KiB
Go

package main
import (
"net"
"testing"
"github.com/magiconair/properties/assert"
)
// Test scafolding
func TestSendLogin(t *testing.T) {
testTable := []struct {
name string
pass string
resultBuffer []byte
resultLenght int
// input, output
}{
{
name: "happy",
pass: "happy2",
resultBuffer: []byte{140, 15, 0, 104, 97, 112, 112, 121, 32, 104, 97, 112, 112, 121, 50, 0, 0},
resultLenght: 17,
},
}
for _, tt := range testTable {
t.Run(tt.name, func(t *testing.T) {
// call function or method under test
// ....
// check respose
server, client := net.Pipe()
go func() {
sendLogin(client, tt.name, tt.pass)
}()
reply := make([]byte, tt.resultLenght)
length, _ := server.Read(reply)
// test length of the received packet
if length != tt.resultLenght {
t.Errorf("Expected length %v, got %v buffer: %v for %s / %s", tt.resultLenght, length, reply[0:length], tt.name, tt.pass)
}
// test content of the packet
assert.Equal(t, reply, tt.resultBuffer, "Login buffers not the same. Check encoding")
})
}
}