Skip to content

Commit

Permalink
CI/CD: setting up ssh server for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
deven96 committed Oct 19, 2021
1 parent 62b2f92 commit 03512c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ vendor/
*.swp
*.swo
*.swp

docker-compose.yaml
15 changes: 9 additions & 6 deletions driver/ssh_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 03512c0

Please sign in to comment.