Skip to content

Commit ded8bed

Browse files
authored
Add some integration tests for SFTP (#232)
1 parent 6e55f5b commit ded8bed

File tree

9 files changed

+206
-3
lines changed

9 files changed

+206
-3
lines changed

.github/workflows/go.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ jobs:
5151
run: go test -v -race -tags=integration_test_minio ./integration
5252
if: matrix.os == 'ubuntu-latest'
5353

54+
- name: Init SFTP
55+
run: chmod +x ./scripts/sftp/*.sh && ./scripts/sftp/init-sftp.sh
56+
if: matrix.os == 'ubuntu-latest'
57+
58+
- name: Test Integration SFTP
59+
run: go test -v -race -tags=integration_test_sftp ./integration
60+
if: matrix.os == 'ubuntu-latest'
61+
5462
- name: Codecov
5563
uses: codecov/codecov-action@v3
5664
if: matrix.os == 'ubuntu-latest'

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/gin-contrib/sessions v0.0.5
1010
github.com/gin-gonic/gin v1.9.1
1111
github.com/minio/minio-go/v7 v7.0.60
12-
github.com/no-src/fsctl v0.1.2-0.20230808162217-242297fbaea4
12+
github.com/no-src/fsctl v0.1.2-0.20230809094346-873969ea2e79
1313
github.com/no-src/log v0.2.3
1414
github.com/no-src/nscache v0.1.1
1515
github.com/pkg/sftp v1.13.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
126126
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
127127
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
128128
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
129-
github.com/no-src/fsctl v0.1.2-0.20230808162217-242297fbaea4 h1:l4/bFYazcDMwBEogCeLwNRVxGtmNYBwLZEoJRqOxdf0=
130-
github.com/no-src/fsctl v0.1.2-0.20230808162217-242297fbaea4/go.mod h1:sXkup5MSxKl0br3AbtkoOhaGD0QSuieO8J3pExKegVs=
129+
github.com/no-src/fsctl v0.1.2-0.20230809094346-873969ea2e79 h1:3I9Vl7r0UAJ7eopzmZzLQQdJkoefvqdENTZ5LJ41qu8=
130+
github.com/no-src/fsctl v0.1.2-0.20230809094346-873969ea2e79/go.mod h1:sXkup5MSxKl0br3AbtkoOhaGD0QSuieO8J3pExKegVs=
131131
github.com/no-src/log v0.2.3 h1:lCJrWeMMuC2Wkp6CKEVylgllH+k4YAm0eRsFX9nVxaQ=
132132
github.com/no-src/log v0.2.3/go.mod h1:C58ahv0WdsBL3Yxi+v6wyUXzwqk7aEPN+/1ltOsdHXg=
133133
github.com/no-src/nscache v0.1.1 h1:gs9hJ4Y5CaeLRmexvE4Rto6Gnjf5maKoTxFnssXAuJE=
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//go:build integration_test_sftp
2+
3+
package integration
4+
5+
import (
6+
"testing"
7+
)
8+
9+
func TestIntegration_SFTP(t *testing.T) {
10+
testCases := []struct {
11+
name string
12+
runServerConf string
13+
runClientConf string
14+
testConf string
15+
}{
16+
{"gofs SFTP push", "", "run-gofs-sftp-push-client.yaml", "test-gofs-sftp-push.yaml"},
17+
{"gofs SFTP pull", "", "run-gofs-sftp-pull-client.yaml", "test-gofs-sftp-pull.yaml"},
18+
}
19+
20+
for _, tc := range testCases {
21+
t.Run(tc.name, func(t *testing.T) {
22+
testIntegrationClientServer(t, tc.runServerConf, tc.runClientConf, tc.testConf)
23+
})
24+
}
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source: sftp://127.0.0.1:22?remote_path=/sftp-workspace
2+
dest: ./sftp-pull-client/dest
3+
log_dir: ./sftp-pull-client-logs/
4+
users: sftp_user|sftp_pwd
5+
sync_cron: "*/5 * * * * *"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source: ./sftp-push-client/source
2+
dest: sftp://127.0.0.1:22?local_sync_disabled=false&path=./sftp-push-client/dest&remote_path=/sftp-workspace
3+
log_dir: ./sftp-push-client-logs/
4+
users: sftp_user|sftp_pwd
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: test for gofs SFTP pull
2+
init:
3+
- mkdir:
4+
source: ./sftp-pull-client/source
5+
- mkdir:
6+
source: ./sftp-pull-client/dest
7+
actions:
8+
- cp:
9+
source: ./integration_sftp_test.go
10+
dest: /sftp-workspace/integration_sftp_test.go.pull.bak1
11+
- cp:
12+
source: ./integration_sftp_test.go
13+
dest: /sftp-workspace/integration_sftp_test.go.pull.bak2
14+
- rm:
15+
source: /sftp-workspace/integration_sftp_test.go.pull.bak2
16+
- touch:
17+
source: /sftp-workspace/hello.pull
18+
- mkdir:
19+
source: /sftp-workspace/work_pull
20+
- sleep: 10s
21+
- is-equal:
22+
source: /sftp-workspace/integration_sftp_test.go.pull.bak1
23+
dest: ./sftp-pull-client/dest/integration_sftp_test.go.pull.bak1
24+
expect: true
25+
must-non-empty: true
26+
- is-exist:
27+
source: ./sftp-pull-client/dest/integration_sftp_test.go.pull.bak2
28+
expect: false
29+
- is-exist:
30+
source: ./sftp-pull-client/dest/hello.pull
31+
expect: true
32+
- is-empty:
33+
source: ./sftp-pull-client/dest/hello.pull
34+
expect: true
35+
- is-dir:
36+
source: ./sftp-pull-client/dest/work_pull
37+
expect: true
38+
clear:
39+
- rm:
40+
source: ./sftp-pull-client
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: test for gofs SFTP push
2+
init:
3+
- mkdir:
4+
source: ./sftp-push-client/source
5+
- mkdir:
6+
source: ./sftp-push-client/dest
7+
actions:
8+
- cp:
9+
source: ./integration_test.go
10+
dest: ./sftp-push-client/source/integration_test.go.bak1
11+
- cp:
12+
source: ./integration_test.go
13+
dest: ./sftp-push-client/source/integration_test.go.bak2
14+
- rm:
15+
source: ./sftp-push-client/source/integration_test.go.bak2
16+
- touch:
17+
source: ./sftp-push-client/source/hello
18+
- echo:
19+
source: ./sftp-push-client/source/hello
20+
input: Hello World
21+
append: false
22+
- echo:
23+
source: ./sftp-push-client/source/hello
24+
input: Bye Bye
25+
append: true
26+
no-newline: false
27+
- echo:
28+
source: ./sftp-push-client/source/empty1
29+
no-newline: true
30+
- echo:
31+
source: ./sftp-push-client/source/empty2
32+
no-newline: true
33+
- symlink:
34+
link: ./sftp-push-client/source/hello.symlink
35+
dest: ./sftp-push-client/source/hello
36+
ignore-error: false
37+
- symlink:
38+
link: ./sftp-push-client/source/hello.symlink.bak
39+
dest: ./sftp-push-client/source/hello
40+
ignore-error: false
41+
- symlink:
42+
link: ./sftp-push-client/source/not_exist.symlink
43+
dest: ./sftp-push-client/source/not_exist
44+
ignore-error: false
45+
- rm:
46+
source: ./sftp-push-client/source/hello.symlink.bak
47+
- sleep: 10s
48+
- is-equal:
49+
source: ./sftp-push-client/source/integration_test.go.bak1
50+
dest: /sftp-workspace/integration_test.go.bak1
51+
expect: true
52+
must-non-empty: true
53+
- is-equal:
54+
source: ./sftp-push-client/source/integration_test.go.bak1
55+
dest: /sftp-workspace/integration_test.go.bak1
56+
expect: true
57+
must-non-empty: true
58+
algorithm: sha1
59+
- is-equal:
60+
source: ./sftp-push-client/source/integration_test.go.bak1
61+
dest: /sftp-workspace/empty1
62+
expect: false
63+
- is-equal:
64+
source: ./sftp-push-client/source/empty1
65+
dest: /sftp-workspace/empty2
66+
expect: true
67+
must-non-empty: false
68+
- is-empty:
69+
source: /sftp-workspace/integration_test.go.bak1
70+
expect: false
71+
- is-exist:
72+
source: /sftp-workspace/integration_test.go.bak1
73+
expect: true
74+
- is-exist:
75+
source: /sftp-workspace/integration_test.go.bak2
76+
expect: false
77+
- is-dir:
78+
source: /sftp-workspace
79+
expect: true
80+
- is-dir:
81+
source: /sftp-workspace/integration_test.go.bak1
82+
expect: false
83+
- hash:
84+
algorithm: md5
85+
source: /sftp-workspace/hello
86+
expect: 856719c57653fa86008d49db895a5752
87+
- hash:
88+
algorithm: sha1
89+
source: /sftp-workspace/hello
90+
expect: f343874b5df87e887d85df2e790df33584463162
91+
- rm:
92+
source: ./sftp-push-client/source/integration_test.go.bak1
93+
- sleep: 10s
94+
- is-exist:
95+
source: /sftp-workspace/integration_test.go.bak1
96+
expect: false
97+
- is-symlink:
98+
link: /sftp-workspace/hello.symlink
99+
expect: true
100+
ignore-error: false
101+
- is-symlink:
102+
link: /sftp-workspace/not_exist.symlink
103+
expect: true
104+
ignore-error: false
105+
- is-exist:
106+
source: /sftp-workspace/hello.symlink.bak
107+
expect: false
108+
clear:
109+
- rm:
110+
source: ./sftp-push-client

scripts/sftp/init-sftp.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
if ! sudo id sftp_user &>/dev/null; then
4+
sudo useradd -m sftp_user
5+
sudo echo "sftp_user:sftp_pwd" | sudo chpasswd
6+
fi
7+
8+
if [ ! -d /sftp-workspace ]; then
9+
sudo mkdir /sftp-workspace
10+
sudo chmod 777 /sftp-workspace
11+
fi

0 commit comments

Comments
 (0)