From 03512c0d53d4089ea1385c07f2db385be740733e Mon Sep 17 00:00:00 2001 From: Diretnan Domnan Date: Tue, 19 Oct 2021 01:21:29 +0100 Subject: [PATCH] CI/CD: setting up ssh server for testing --- .github/workflows/test.yml | 16 +++++++++++++++- .gitignore | 2 ++ driver/ssh_test.go | 15 +++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 51cb5f8..b087e51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,20 @@ jobs: go-version: ${{ matrix.go-version }} - name: Checkout code uses: actions/checkout@v2 - - name: Test + - name: Setup SSH server # run docker ssh container for ssh tests + run: | + mkdir -p /home/runner/.ssh + echo "${{ secrets.TEST_PUB_KEY }}" >> /home/runner/.ssh/id_rsa.pub + echo "${{ secrets.TEST_PRIV_KEY }}" >> /home/runner/.ssh/id_rsa + docker run -d \ + -e PASSWORD_ACCESS=false \ + -e PGID=1000 \ + -e PUID=1000 \ + -e SUDO_ACCESS=false \ + -e USER_NAME=dev \ + -e PUBLIC_KEY_FILE=/root/.ssh/id_rsa.pub \ + -v /home/runner/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub \ + linuxserver/openssh-server + - name: Test run: go test -v ./... diff --git a/.gitignore b/.gitignore index 9a164a4..c0af780 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ vendor/ *.swp *.swo *.swp + +docker-compose.yaml diff --git a/driver/ssh_test.go b/driver/ssh_test.go index 28b74ab..95c3830 100644 --- a/driver/ssh_test.go +++ b/driver/ssh_test.go @@ -1,18 +1,21 @@ package driver -import "testing" +import ( + "strings" + "testing" +) func TestSSHRunCommand(t *testing.T) { d := SSH{ - User: "root", - Host: "172.17.0.2", + User: "dev", + Host: "127.0.0.1", Port: 2222, - PubKeyFile: "/home/deven/.ssh/id_rsa", + PubKeyFile: "/home/runner/.ssh/id_rsa", PubKeyPass: "", CheckKnownHosts: false, } - _, err := d.runCommand(`ps -A`) - if err != nil { + output, err := d.runCommand(`ps -A`) + if err != nil || !strings.Contains(output, "PID") { t.Error(err) } }