diff --git a/internal/db/db_test.go b/internal/db/db_test.go index 041408e..54572ab 100644 --- a/internal/db/db_test.go +++ b/internal/db/db_test.go @@ -1,16 +1,17 @@ -package db +package db_test import ( "context" "os" "testing" + "github.com/CPunch/gopenfusion/internal/db" "github.com/CPunch/gopenfusion/internal/protocol" "github.com/bitcomplete/sqltestutil" ) var ( - testDB *DBHandler + testDB *db.DBHandler ) func TestMain(m *testing.M) { @@ -21,7 +22,7 @@ func TestMain(m *testing.M) { } defer psql.Shutdown(ctx) - testDB, err = OpenFromConnectionString("postgres", psql.ConnectionString()+"?sslmode=disable") + testDB, err = db.OpenFromConnectionString("postgres", psql.ConnectionString()+"?sslmode=disable") if err != nil { panic(err) } @@ -49,7 +50,7 @@ func TestDBAccount(t *testing.T) { t.Error("account username is not test") } - if _, err = testDB.TryLogin("test", "wrongpassword"); err != ErrLoginInvalidPassword { + if _, err = testDB.TryLogin("test", "wrongpassword"); err != db.ErrLoginInvalidPassword { t.Error("expected ErrLoginInvalidPassword") } } diff --git a/internal/protocol/packet_test.go b/internal/protocol/protocol_test.go similarity index 54% rename from internal/protocol/packet_test.go rename to internal/protocol/protocol_test.go index 5a1ee41..0e950c9 100644 --- a/internal/protocol/packet_test.go +++ b/internal/protocol/protocol_test.go @@ -1,8 +1,10 @@ -package protocol +package protocol_test import ( "bytes" "testing" + + "github.com/CPunch/gopenfusion/internal/protocol" ) type TestPacketData struct { @@ -21,10 +23,23 @@ type TestPacketData struct { // UTF16Str: "hello world", // C: 3, // }) -var testData = [...]byte{0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00, 0x20, 0x00, 0x77, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x6c, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00} +var testData = [...]byte{ + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, + 0x6f, 0x00, 0x20, 0x00, 0x77, 0x00, 0x6f, 0x00, + 0x72, 0x00, 0x6c, 0x00, 0x64, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, +} func TestPacketEncodeDecode(t *testing.T) { - pkt := NewPacket(&bytes.Buffer{}) + buf := &bytes.Buffer{} + pkt := protocol.NewPacket(buf) + if err := pkt.Encode(TestPacketData{ A: 1, B: 2, @@ -34,7 +49,7 @@ func TestPacketEncodeDecode(t *testing.T) { t.Error(err) } - if !bytes.Equal(pkt.readWriter.(*bytes.Buffer).Bytes(), testData[:]) { + if !bytes.Equal(buf.Bytes(), testData[:]) { t.Error("packet data does not match!") }