mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-12-04 22:46:32 +00:00
Compare commits
5 Commits
4419260cd0
...
b02c141000
Author | SHA1 | Date | |
---|---|---|---|
b02c141000 | |||
5b78c3dbd4 | |||
d31723e245 | |||
bb50948935 | |||
d32facf363 |
22
.github/workflows/tests.yaml
vendored
Normal file
22
.github/workflows/tests.yaml
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
name: Go
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- ./**.go
|
||||||
|
- go.mod
|
||||||
|
- go.sum
|
||||||
|
- .github/workflows/tests.yaml
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '1.21.x'
|
||||||
|
- name: Test with the Go CLI
|
||||||
|
run: go test -v ./...
|
@ -1,16 +1,17 @@
|
|||||||
package db
|
package db_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/CPunch/gopenfusion/internal/db"
|
||||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||||
"github.com/bitcomplete/sqltestutil"
|
"github.com/bitcomplete/sqltestutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testDB *DBHandler
|
testDB *db.DBHandler
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
@ -21,7 +22,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
defer psql.Shutdown(ctx)
|
defer psql.Shutdown(ctx)
|
||||||
|
|
||||||
testDB, err = OpenFromConnectionString("postgres", psql.ConnectionString()+"?sslmode=disable")
|
testDB, err = db.OpenFromConnectionString("postgres", psql.ConnectionString()+"?sslmode=disable")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ func TestDBAccount(t *testing.T) {
|
|||||||
t.Error("account username is not test")
|
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")
|
t.Error("expected ErrLoginInvalidPassword")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
40
internal/entity/entity_test.go
Normal file
40
internal/entity/entity_test.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package entity_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/CPunch/gopenfusion/internal/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestChunkSliceDifference(t *testing.T) {
|
||||||
|
chunks := []*entity.Chunk{
|
||||||
|
entity.NewChunk(entity.MakeChunkPosition(0, 0)),
|
||||||
|
entity.NewChunk(entity.MakeChunkPosition(0, 1)),
|
||||||
|
entity.NewChunk(entity.MakeChunkPosition(1, 0)),
|
||||||
|
entity.NewChunk(entity.MakeChunkPosition(1, 1)),
|
||||||
|
}
|
||||||
|
|
||||||
|
c1 := []*entity.Chunk{
|
||||||
|
chunks[0],
|
||||||
|
chunks[1],
|
||||||
|
chunks[2],
|
||||||
|
chunks[3],
|
||||||
|
}
|
||||||
|
|
||||||
|
c2 := []*entity.Chunk{
|
||||||
|
chunks[0],
|
||||||
|
chunks[1],
|
||||||
|
chunks[2],
|
||||||
|
}
|
||||||
|
|
||||||
|
diff := entity.ChunkSliceDifference(c1, c2)
|
||||||
|
if len(diff) != 1 {
|
||||||
|
t.Logf("%+v", diff)
|
||||||
|
t.Error("expected 1 chunk in difference")
|
||||||
|
}
|
||||||
|
|
||||||
|
if diff[0] != chunks[3] {
|
||||||
|
t.Logf("%+v", diff)
|
||||||
|
t.Error("wrong difference")
|
||||||
|
}
|
||||||
|
}
|
@ -49,7 +49,7 @@ func DecryptData(buff, key []byte) {
|
|||||||
xorData(buff, key, size)
|
xorData(buff, key, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateNewKey(uTime uint64, iv1, iv2 uint64) []byte {
|
func CreateNewKey(uTime, iv1, iv2 uint64) []byte {
|
||||||
num := iv1 + 1
|
num := iv1 + 1
|
||||||
num2 := iv2 + 1
|
num2 := iv2 + 1
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package protocol
|
package protocol_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestPacketData struct {
|
type TestPacketData struct {
|
||||||
@ -21,10 +23,23 @@ type TestPacketData struct {
|
|||||||
// UTF16Str: "hello world",
|
// UTF16Str: "hello world",
|
||||||
// C: 3,
|
// 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) {
|
func TestPacketEncodeDecode(t *testing.T) {
|
||||||
pkt := NewPacket(&bytes.Buffer{})
|
buf := &bytes.Buffer{}
|
||||||
|
pkt := protocol.NewPacket(buf)
|
||||||
|
|
||||||
if err := pkt.Encode(TestPacketData{
|
if err := pkt.Encode(TestPacketData{
|
||||||
A: 1,
|
A: 1,
|
||||||
B: 2,
|
B: 2,
|
||||||
@ -34,7 +49,7 @@ func TestPacketEncodeDecode(t *testing.T) {
|
|||||||
t.Error(err)
|
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!")
|
t.Error("packet data does not match!")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user