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

Commit

Permalink
feat: Implement integration test (#16)
Browse files Browse the repository at this point in the history
* feat: Implement basic credential

* Create integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* fix: Add fallback check for list

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* Update integration-test.yml

* update: Integration test

* fix: remove irrelated codes

* Update integration-test.yml

* Update integration-test.yml
  • Loading branch information
npofsi authored Aug 12, 2021
1 parent 54d3b08 commit f932d8b
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 16 deletions.
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

0 comments on commit f932d8b

Please sign in to comment.