Skip to content

Commit 8a84c86

Browse files
Merge pull request #4 from gopasspw/fix/disp
[fix] Attempt to fix tests that need display on linux
2 parents 83d8abd + b1fcbfc commit 8a84c86

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Harden Runner
2323
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
2424
with:
25-
egress-policy: block
25+
egress-policy: audit
2626
allowed-endpoints: >
2727
github.com:443
2828
objects.githubusercontent.com:443
@@ -51,7 +51,7 @@ jobs:
5151
restore-keys: |
5252
${{ runner.os }}-go-
5353
- name: Ubuntu Dependencies
54-
run: sudo apt-get install --yes wl-clipboard xclip xsel
54+
run: sudo apt-get install --yes wl-clipboard xclip xsel xvfb x11-xserver-utils
5555

5656
-
5757
name: Debug
@@ -62,10 +62,23 @@ jobs:
6262
echo ${GITHUB_WORKSPACE}
6363
echo ${GOPATH}
6464
echo ${GOROOT}
65-
env
65+
echo ${DISPLAY}
66+
env
6667
6768
- name: Build and Unit Test
68-
run: go test ./...
69+
run: xvfb-run --auto-servernum go test ./...
70+
71+
- name: cleanup xvfb
72+
run: |
73+
xvfb_pids=`ps aux | grep tmp/xvfb-run | grep -v grep | awk '{print $2}'`
74+
if [ "$xvfb_pids" != "" ]; then
75+
echo "Killing the following xvfb processes: $xvfb_pids"
76+
sudo kill $xvfb_pids
77+
else
78+
echo "No xvfb processes to kill"
79+
fi
80+
env:
81+
CI: true
6982

7083
windows:
7184
runs-on: windows-latest

clipboard_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55
package clipboard_test
66

77
import (
8-
"os"
9-
"runtime"
108
"testing"
119

1210
. "github.com/gopasspw/clipboard"
1311
)
1412

1513
func TestCopyAndPaste(t *testing.T) {
16-
if runtime.GOOS == "linux" && os.Getenv("WAYLAND_DISPLAY") == "" && os.Getenv("DISPLAY") == "" {
17-
t.Skip("Skipping test on Linux without Wayland or X11")
18-
}
19-
2014
expected := "日本語"
2115

2216
err := WriteAllString(t.Context(), expected)
@@ -35,10 +29,6 @@ func TestCopyAndPaste(t *testing.T) {
3529
}
3630

3731
func TestMultiCopyAndPaste(t *testing.T) {
38-
if runtime.GOOS == "linux" && os.Getenv("WAYLAND_DISPLAY") == "" && os.Getenv("DISPLAY") == "" {
39-
t.Skip("Skipping test on Linux without Wayland or X11")
40-
}
41-
4232
expected1 := "French: éèêëàùœç"
4333
expected2 := "Weird UTF-8: 💩☃"
4434

clipboard_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func readAll(ctx context.Context) ([]byte, error) {
158158
if w.trimDOS && len(result) > 1 {
159159
result = result[:len(result)-2]
160160
}
161+
161162
return result, nil
162163
}
163164

@@ -190,6 +191,7 @@ func writeAll(ctx context.Context, text []byte, secret bool) error {
190191
if err := copyCmd.Wait(); err != nil {
191192
return fmt.Errorf("failed to wait for command: %w", err)
192193
}
194+
193195
return nil
194196
}
195197

example_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
//go:build interactive
2-
// +build interactive
3-
41
package clipboard_test
52

63
import (
4+
"context"
75
"fmt"
86

97
"github.com/gopasspw/clipboard"
108
)
119

1210
func Example() {
13-
clipboard.WriteAllString("日本語") //nolint:errcheck
14-
text, _ := clipboard.ReadAllString() //nolint:errcheck
11+
clipboard.WriteAllString(context.TODO(), "日本語") //nolint:errcheck
12+
text, _ := clipboard.ReadAllString(context.TODO()) //nolint:errcheck
1513
fmt.Println(text)
1614

1715
// Output:

0 commit comments

Comments
 (0)