diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0519eac9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM golang:1.22-alpine +RUN apk update && apk add shadow +RUN groupadd -g 1000 test && useradd -u 1000 -g 1000 -m -d /usr/src/app test +WORKDIR /usr/src/app +COPY . . +RUN chown -R test:test . +USER test:test +CMD [ "go", "test", "./..." ] diff --git a/README.md b/README.md index 7639881a..b9bc94f4 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ To make a release of go-sftp simply open a pull request with `CHANGELOG.md` and ### Testing -We maintain a comprehensive suite of unit tests and recommend table-driven testing when a particular function warrants several very similar test cases. After starting the services with Docker Compose run all tests with `go test ./...`. Current overall coverage can be found on [Codecov](https://app.codecov.io/gh/moov-io/go-sftp/). +We maintain a comprehensive suite of unit tests and recommend table-driven testing when a particular function warrants several very similar test cases. Run tests with `docker compose up --abort-on-container-exit --exit-code-from testrunner`. Current overall coverage can be found on [Codecov](https://app.codecov.io/gh/moov-io/go-sftp/). ## License diff --git a/client_test.go b/client_test.go index ab8ef6ba..4c5274ec 100644 --- a/client_test.go +++ b/client_test.go @@ -42,7 +42,7 @@ func TestClient(t *testing.T) { } client, err := sftp.NewClient(log.NewTestLogger(), &sftp.ClientConfig{ - Hostname: "localhost:2222", + Hostname: "sftp:22", Username: "demo", Password: "password", Timeout: 5 * time.Second, @@ -288,7 +288,7 @@ func TestClient__UploadFile(t *testing.T) { } conf := &sftp.ClientConfig{ - Hostname: "localhost:2222", + Hostname: "sftp:22", Username: "demo", Password: "password", Timeout: 5 * time.Second, diff --git a/docker-compose.yml b/docker-compose.yml index 98f6408a..3c551f5e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,29 @@ version: '3.7' + +networks: + test-net: {} + services: sftp: image: atmoz/sftp:latest - ports: - - "2222:22" volumes: - "./testdata/outbox:/home/demo/outbox" - "./testdata/bigdata:/home/demo/bigdata" - "./testdata/root.txt:/home/demo/root.txt" command: - "demo:password:::outbox,upload" + healthcheck: + test: ["CMD-SHELL", "bash -c 'exec 6<> /dev/tcp/localhost/22'"] + interval: 2s + networks: + - test-net + + testrunner: + depends_on: + sftp: + condition: service_healthy + build: + context: . + dockerfile: Dockerfile + networks: + - test-net diff --git a/network_test.go b/network_test.go index 5fc784f1..a35c254a 100644 --- a/network_test.go +++ b/network_test.go @@ -19,7 +19,7 @@ func TestNetwork(t *testing.T) { } client, err := sftp.NewClient(log.NewTestLogger(), &sftp.ClientConfig{ - Hostname: "localhost:2222", + Hostname: "sftp:22", Username: "demo", Password: "password", Timeout: 5 * time.Second,