Skip to content

Commit 7f0df65

Browse files
committed
Add testing
1 parent efa1529 commit 7f0df65

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

.github/workflows/github-actions.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ jobs:
2121
mingw-w64-${{ matrix.env }}-toolchain
2222
mingw-w64-${{ matrix.env }}-go
2323
- name: Build executables
24-
env:
25-
GOARCH: ${{ matrix.arch }}
26-
CGO_ENABLED: 1
2724
shell: msys2 {0}
2825
run: |
2926
mkdir build
3027
${{ matrix.env }}-w64-mingw32-gcc -o build/test-discon_${{ matrix.arch }}.dll test-discon/test-discon.c --shared -g
3128
${{ matrix.env }}-w64-mingw32-gcc -o build/test-app_${{ matrix.arch }}.exe test-app/test-app.c -g
3229
go build -o build/discon-server_${{ matrix.arch }}.exe discon-wrapper/discon-server
33-
go build -buildmode=c-shared -o build/discon-client_${{ matrix.arch }}.exe discon-wrapper/discon-client
30+
go build -buildmode=c-shared -o build/discon-client_${{ matrix.arch }}.dll discon-wrapper/discon-client
3431
- uses: actions/upload-artifact@v4
3532
with:
3633
name: windows-binaries-${{ matrix.arch }}
3734
path: build/*
35+
- name: Test discon-server
36+
shell: msys2 {0}
37+
run: go test discon-wrapper/discon-server
3838

3939
# build-and-test-linux:
4040
# runs-on: ubuntu-latest

discon-server/server_test.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func TestServeWs(t *testing.T) {
1515

16-
const port = 8080
16+
const port = 8081
1717

1818
// connect handler to websocket function
1919
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
@@ -38,7 +38,7 @@ func TestServeWs(t *testing.T) {
3838

3939
// Add query parameters for shared library path and proc
4040
q := u.Query()
41-
q.Add("path", "../test-discon/test-discon.dll")
41+
q.Add("path", "../build/test-discon.dll")
4242
q.Add("proc", "discon")
4343
u.RawQuery = q.Encode()
4444

@@ -54,7 +54,7 @@ func TestServeWs(t *testing.T) {
5454
Fail: 1,
5555
InFile: []byte("input.txt\u0000"),
5656
OutName: []byte("output.txt\u0000"),
57-
Msg: []byte("Hello, World!\u0000"),
57+
Msg: []byte("Hello, World! \u0000"),
5858
}
5959
payload.Swap[48] = float32(len(payload.Msg))
6060
payload.Swap[49] = float32(len(payload.InFile))
@@ -68,35 +68,42 @@ func TestServeWs(t *testing.T) {
6868
}
6969
ws.WriteMessage(websocket.BinaryMessage, b)
7070

71+
t.Log("Client sent payload:", payload)
72+
73+
// Clear data in payload
74+
payload.Swap = make([]float32, len(payload.Swap))
75+
payload.Fail = -1
76+
payload.InFile = make([]byte, len(payload.InFile))
77+
payload.OutName = make([]byte, len(payload.OutName))
78+
payload.Msg = make([]byte, len(payload.Msg))
79+
7180
// Read response from server
7281
_, b, err = ws.ReadMessage()
7382
if err != nil {
7483
t.Fatal(err)
7584
}
7685

77-
fmt.Println("Client sent payload:", payload)
78-
7986
// Unmarshal binary data into payload
8087
err = payload.UnmarshalBinary(b)
8188
if err != nil {
8289
t.Fatal(err)
8390
}
8491

8592
// Print payload
86-
fmt.Println("Client received payload:", payload)
93+
t.Log("Client received payload:", payload)
8794

8895
// Check if the payload is correct
8996
if payload.Fail != 0 {
9097
t.Errorf("Expected Fail to be 0, got %d", payload.Fail)
9198
}
9299
if string(payload.InFile) != "input.txt\u0000" {
93-
t.Errorf("Expected InFile to be 'input.txt\\u0000', got %s", string(payload.InFile))
100+
t.Errorf("Expected InFile to be 'input.txt\\u0000', got '%s'", string(payload.InFile))
94101
}
95102
if string(payload.OutName) != "output.txt\u0000" {
96-
t.Errorf("Expected OutName to be 'output.txt\\u0000', got %s", string(payload.OutName))
103+
t.Errorf("Expected OutName to be 'output.txt\\u0000', got '%s'", string(payload.OutName))
97104
}
98-
if string(payload.Msg) != "Welcome! \u0000" {
99-
t.Errorf("Expected Msg to be 'Welcome! \\u0000', got %s", string(payload.Msg))
105+
if string(payload.Msg) != "DISCON called 1 times\u0000" {
106+
t.Errorf("Expected Msg to be 'DISCON called 1 times\\u0000', got '%s'", string(payload.Msg))
100107
}
101108
if len(payload.Swap) != 130 {
102109
t.Errorf("Expected Swap to be of length 130, got %d", len(payload.Swap))

0 commit comments

Comments
 (0)