From cafc139713b9444bbe292f7e0009ca33ee32fd25 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 16 Mar 2024 11:29:44 +0800 Subject: [PATCH] test: enhance testing and internal API robustness (#269) * test: support ipv6 * chore: update Signed-off-by: appleboy * chore: update Signed-off-by: appleboy --------- Signed-off-by: appleboy --- .github/workflows/lint.yml | 4 ++- plugin_test.go | 57 ++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 51605ec..d692934 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -27,7 +27,9 @@ jobs: testing: runs-on: ubuntu-latest - container: golang:1.21-alpine + container: + image: golang:1.21-alpine + options: --sysctl net.ipv6.conf.all.disable_ipv6=0 steps: - name: Checkout repository uses: actions/checkout@v3 diff --git a/plugin_test.go b/plugin_test.go index 251b425..8674bca 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -432,7 +432,6 @@ func getHostPublicKeyFile(keypath string) (ssh.PublicKey, error) { } pubkey, _, _, _, err = ssh.ParseAuthorizedKey(buf) - if err != nil { return nil, err } @@ -965,33 +964,31 @@ func TestSudoCommand(t *testing.T) { assert.Equal(t, unindent(expected), unindent(buffer.String())) } -// TODO: TestCommandWithIPv6 is not working on github actions. -// func TestCommandWithIPv6(t *testing.T) { -// var ( -// buffer bytes.Buffer -// expected = ` -// ======CMD====== -// whoami -// ======END====== -// out: drone-scp -// ` -// ) +func TestCommandWithIPv6(t *testing.T) { + var ( + buffer bytes.Buffer + expected = ` + ======CMD====== + whoami + ======END====== + out: drone-scp + ` + ) -// plugin := Plugin{ -// Config: Config{ -// Host: []string{"::1"}, -// Username: "drone-scp", -// Port: 22, -// KeyPath: "./tests/.ssh/id_rsa", -// Script: []string{ -// "whoami", -// }, -// Protocol: easyssh.PROTOCOL_TCP6, -// CommandTimeout: 10 * time.Second, -// }, -// Writer: &buffer, -// } - -// assert.Nil(t, plugin.Exec()) -// assert.Equal(t, unindent(expected), unindent(buffer.String())) -// } + plugin := Plugin{ + Config: Config{ + Host: []string{"::1"}, + Username: "drone-scp", + Port: 22, + KeyPath: "./tests/.ssh/id_rsa", + Script: []string{ + "whoami", + }, + Protocol: easyssh.PROTOCOL_TCP6, + CommandTimeout: 10 * time.Second, + }, + Writer: &buffer, + } + assert.Nil(t, plugin.Exec()) + assert.Equal(t, unindent(expected), unindent(buffer.String())) +}