Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

feat: Implement integration test #16

Merged
merged 29 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f0e1cc4
feat: Implement basic credential
npofsi Aug 6, 2021
cc46bbe
Create integration-test.yml
npofsi Aug 7, 2021
db910d6
Update integration-test.yml
npofsi Aug 7, 2021
e77794d
Update integration-test.yml
npofsi Aug 7, 2021
e0ae194
Update integration-test.yml
npofsi Aug 7, 2021
558ef01
Update integration-test.yml
npofsi Aug 7, 2021
365a2af
Update integration-test.yml
npofsi Aug 7, 2021
9758f53
Update integration-test.yml
npofsi Aug 7, 2021
7b28a8e
fix: Add fallback check for list
npofsi Aug 8, 2021
9d6440d
Update integration-test.yml
npofsi Aug 8, 2021
a8479b1
Update integration-test.yml
npofsi Aug 8, 2021
c3c9753
Update integration-test.yml
npofsi Aug 8, 2021
6ddc53e
Update integration-test.yml
npofsi Aug 8, 2021
6378205
Update integration-test.yml
npofsi Aug 8, 2021
e4c2ca0
Update integration-test.yml
npofsi Aug 8, 2021
670058f
Update integration-test.yml
npofsi Aug 8, 2021
045ff61
Update integration-test.yml
npofsi Aug 8, 2021
839db93
Update integration-test.yml
npofsi Aug 8, 2021
cfc24fa
Update integration-test.yml
npofsi Aug 8, 2021
0168937
Update integration-test.yml
npofsi Aug 8, 2021
120e477
Update integration-test.yml
npofsi Aug 8, 2021
0ad8073
Update integration-test.yml
npofsi Aug 8, 2021
328535b
Update integration-test.yml
npofsi Aug 8, 2021
48d7b34
update: Integration test
npofsi Aug 9, 2021
e904e88
fix: remove irrelated codes
npofsi Aug 9, 2021
aea3b0b
Merge branch 'master' into feature
npofsi Aug 9, 2021
b4891b7
Update integration-test.yml
npofsi Aug 9, 2021
5460640
Merge branch 'master' into feature
npofsi Aug 11, 2021
2ccfa62
Update integration-test.yml
npofsi Aug 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Integration Test"

on: [push, pull_request]

jobs:
integration_test:
name: Integration Test
runs-on: ${{ matrix.os }}
env:
STORAGE_FTP_INTEGRATION_TEST: on
STORAGE_FTP_CREDENTIAL: basic:user:password
STORAGE_FTP_ENDPOINT: tcp:127.0.0.1:2121

strategy:
matrix:
go: ["1.15", "1.16"]
os: [ubuntu-latest]

steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Checkout repository
uses: actions/checkout@v2

- name: Download ftpserver release
uses: robinraju/[email protected]
with:
repository: fclairamb/ftpserver
tag: v0.10.0
fileName: ftpserver-linux-amd64

- name: Prepare config file
run: mv ./tests/ftpserver.json ./ftpserver.json

- name: Create test dir
run: mkdir tmp

- name: Start ftp server
run: |
chmod 777 ftpserver-linux-amd64
./ftpserver-linux-amd64 &

- name: Build
run: make build

- name: Integration Test
run: make integration_test
4 changes: 3 additions & 1 deletion Makefile.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export STORAGE_FTP_INTEGRATION_TEST=on
export STORAGE_FTP_INTEGRATION_TEST=on
export STORAGE_FTP_CREDENTIAL=basic:user:password
export STORAGE_FTP_ENDPOINT=tcp:127.0.0.1:2121
2 changes: 2 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Set following environment variables:

```shell
export STORAGE_FTP_INTEGRATION_TEST=on
export STORAGE_FTP_CREDENTIAL=basic:user:password
export STORAGE_FTP_ENDPOINT=tcp:127.0.0.1:2121
```

Run tests
Expand Down
20 changes: 20 additions & 0 deletions tests/ftpserver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 1,
"accesses": [
{
"sync_and_delete": {
"enable": true
},
"user": "user",
"pass": "password",
"fs": "os",
"params": {
"basePath": "./tmp"
}
}
],
"passive_transfer_port_range": {
"start": 2122,
"end": 2130
}
}
10 changes: 8 additions & 2 deletions tests/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package tests

import (
"os"
"testing"

ftp "github.com/beyondstorage/go-service-ftp"
_ "github.com/beyondstorage/go-service-ftp"
ps "github.com/beyondstorage/go-storage/v4/pairs"
"github.com/beyondstorage/go-storage/v4/services"
"github.com/beyondstorage/go-storage/v4/types"
)

func initTest(t *testing.T) (store types.Storager) {
t.Log("Setup test for ftp")

store, err := ftp.NewStorager()
store, err := services.NewStorager("ftp",
ps.WithCredential(os.Getenv("STORAGE_FTP_CREDENTIAL")),
ps.WithEndpoint(os.Getenv("STORAGE_FTP_ENDPOINT")),
)
if err != nil {
t.Errorf("create storager: %v", err)
}
Expand Down
25 changes: 12 additions & 13 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,18 @@ func newStorager(pairs ...types.Pair) (store *Storage, err error) {
store.workDir = opt.WorkDir
}

if opt.HasCredential {
cp, err := credential.Parse(opt.Credential)
if err != nil {
return nil, err
}
switch cp.Protocol() {
case credential.ProtocolBasic:
user, pass := cp.Basic()
store.password = pass
store.user = user
default:
return nil, services.PairUnsupportedError{Pair: ps.WithCredential(opt.Credential)}
}
cp, err := credential.Parse(opt.Credential)
if err != nil {
return nil, err
}
switch cp.Protocol() {
case credential.ProtocolBasic:
user, pass := cp.Basic()
store.password = pass
store.user = user
default:
return nil, services.PairUnsupportedError{Pair: ps.WithCredential(opt.Credential)}

}

err = store.connect()
Expand Down