diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 0000000..cec11c0 --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -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/release-downloader@v1.1 + 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 diff --git a/Makefile.env.example b/Makefile.env.example index 8b82f8b..fee84c8 100644 --- a/Makefile.env.example +++ b/Makefile.env.example @@ -1 +1,3 @@ -export STORAGE_FTP_INTEGRATION_TEST=on \ No newline at end of file +export STORAGE_FTP_INTEGRATION_TEST=on +export STORAGE_FTP_CREDENTIAL=basic:user:password +export STORAGE_FTP_ENDPOINT=tcp:127.0.0.1:2121 \ No newline at end of file diff --git a/tests/README.md b/tests/README.md index e3eee8a..40354b3 100644 --- a/tests/README.md +++ b/tests/README.md @@ -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 diff --git a/tests/ftpserver.json b/tests/ftpserver.json new file mode 100644 index 0000000..1be5a93 --- /dev/null +++ b/tests/ftpserver.json @@ -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 + } +} diff --git a/tests/utils_test.go b/tests/utils_test.go index 0a0b203..063f6fc 100644 --- a/tests/utils_test.go +++ b/tests/utils_test.go @@ -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) } diff --git a/utils.go b/utils.go index d86bc48..1ca21fa 100644 --- a/utils.go +++ b/utils.go @@ -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()