Skip to content

Commit 4f6fcdd

Browse files
committed
webview test
1 parent 826532a commit 4f6fcdd

15 files changed

Lines changed: 517 additions & 302 deletions

.github/workflows/test.yml

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,54 +53,73 @@ jobs:
5353
- uses: actions/setup-go@v5
5454
with:
5555
go-version: ${{ env.GO_VERSION }}
56+
- name: Install webview dependencies
57+
run: |
58+
sudo apt-get update -y
59+
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev xvfb
5660
- name: Run Unit tests.
5761
run: |
5862
# Get packages for testing and coverage (including cmd/web for flags_test.go)
59-
PACKAGES=$(go list ./... | grep -v /bind/ | grep -v -E '/cmd/(?!web)')
60-
go test -v -coverpkg=$(echo "$PACKAGES" | paste -sd "," -) -covermode=count -coverprofile=coverage.txt $PACKAGES
63+
PACKAGES=$(go list ./... | awk '!/\/bind\// && (!/\/cmd\// || /\/cmd\/web$/)')
64+
env CGO_ENABLED=1 xvfb-run -a go test -tags webview -v -coverpkg=$(echo "$PACKAGES" | paste -sd "," -) -covermode=count -coverprofile=coverage.txt $PACKAGES
6165
# Filter out main.go from coverage report to avoid lowering coverage percentage
6266
grep -v "main.go" coverage.txt > coverage_filtered.txt || true
6367
mv coverage_filtered.txt coverage.txt
6468
- uses: codecov/codecov-action@v4
6569
with:
6670
files: ./coverage.txt
6771
token: ${{ secrets.CODECOV_UPLOAD_TOKEN }}
68-
test-webview:
69-
name: Test webview (${{ matrix.os }})
72+
test-webview-integration:
73+
name: Test webview integration (${{ matrix.name }})
7074
strategy:
7175
fail-fast: false
7276
matrix:
73-
os: [ ubuntu-22.04, macos-latest, windows-latest ]
77+
include:
78+
- name: Windows
79+
os: windows-latest
80+
- name: macOS
81+
os: macos-latest
7482
runs-on: ${{ matrix.os }}
7583
steps:
7684
- uses: actions/checkout@v3
7785
- uses: actions/setup-go@v5
7886
with:
7987
go-version: ${{ env.GO_VERSION }}
80-
- name: Install webview dependencies (Linux)
81-
if: runner.os == 'Linux'
82-
run: |
83-
sudo apt-get update -y
84-
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev xvfb
85-
- name: Build check (CGO enabled)
86-
run: CGO_ENABLED=1 go build -tags webview ./internal/webview/goprovider/
87-
shell: bash
88-
- name: Go vet
89-
run: CGO_ENABLED=1 go vet -tags webview ./internal/webview/goprovider/
90-
shell: bash
91-
- name: Test webview (Linux)
92-
if: runner.os == 'Linux'
93-
run: xvfb-run CGO_ENABLED=1 go test -tags webview -v -timeout 120s
94-
./internal/webview/goprovider/
95-
- name: Test webview (macOS)
88+
- uses: subosito/flutter-action@v2
9689
if: runner.os == 'macOS'
97-
run: CGO_ENABLED=1 go test -tags webview -v -timeout 120s
98-
./internal/webview/goprovider/
99-
- name: Test webview (Windows)
90+
with:
91+
flutter-version: ${{ env.FLUTTER_VERSION }}
92+
- name: Test webview
10093
if: runner.os == 'Windows'
101-
run: go test -tags webview -v -timeout 120s ./internal/webview/goprovider/
94+
run: go test -tags webview -v -timeout 300s ./internal/webview/goprovider/
10295
env:
10396
CGO_ENABLED: 1
97+
- name: Test webview
98+
if: runner.os == 'macOS'
99+
shell: bash
100+
run: |
101+
set -euo pipefail
102+
SOCKET_PATH="$HOME/Library/Application Support/com.gopeed.gopeed/gopeed_webview.sock"
103+
LOG_PATH="$RUNNER_TEMP/gopeed-webview-rpc.log"
104+
rm -f "$SOCKET_PATH"
105+
106+
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o ui/flutter/macos/Frameworks/libgopeed.dylib github.com/GopeedLab/gopeed/bind/desktop
107+
108+
cd ui/flutter
109+
flutter pub get
110+
flutter run -d macos >"$LOG_PATH" 2>&1 &
111+
FLUTTER_PID=$!
112+
cd ../..
113+
114+
cleanup() {
115+
kill "$FLUTTER_PID" >/dev/null 2>&1 || true
116+
}
117+
trap cleanup EXIT
118+
119+
if ! go test -tags webview -v -timeout 600s ./internal/webview/rpcprovider/ -args -webview-rpc-network unix -webview-rpc-address "$SOCKET_PATH"; then
120+
cat "$LOG_PATH"
121+
exit 1
122+
fi
104123
105124
build-desktop:
106125
strategy:

bind/desktop/webview_provider_darwin_test.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

bind/desktop/webview_provider_other_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

internal/webview/goprovider/provider_cgo.go renamed to internal/webview/goprovider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build cgo && webview
1+
//go:build cgo
22

33
package goprovider
44

internal/webview/goprovider/provider_cgo_test.go

Lines changed: 0 additions & 199 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build cgo && webview && !darwin
2+
3+
package goprovider
4+
5+
import (
6+
"testing"
7+
8+
"github.com/GopeedLab/gopeed/internal/webview/integrationtest"
9+
)
10+
11+
func TestProviderContract(t *testing.T) {
12+
integrationtest.RunProviderContract(t, New(), integrationtest.ContractOptions{
13+
CookieDomainMode: integrationtest.CookieDomainModeRequired,
14+
})
15+
}

internal/webview/goprovider/provider_stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !cgo || !webview
1+
//go:build !cgo
22

33
package goprovider
44

0 commit comments

Comments
 (0)