refoctor: ssh logic (#194)

* feat: optimize ssh
This commit is contained in:
naison
2024-03-08 19:16:29 +08:00
committed by GitHub
parent f3d1c99a04
commit 600e35b8d7
4 changed files with 150 additions and 34 deletions

View File

@@ -0,0 +1,49 @@
package handler
import "testing"
func TestGetVersionFromOutput(t *testing.T) {
tests := []struct {
output string
version string
}{
{
output: `KubeVPN: CLI
Version: v2.2.3
DaemonVersion: v2.2.3
Image: docker.io/naison/kubevpn:v2.2.3
Branch: feat/ssh-heartbeat
Git commit: 1272e86a337d3075427ee3a1c3681d378558d133
Built time: 2024-03-08 17:14:49
Built OS/Arch: darwin/arm64
Built Go version: go1.20.5`,
version: "v2.2.3",
},
{
output: `KubeVPN: CLI
Version: v2.2.3
DaemonVersion: unknown
Image: docker.io/naison/kubevpn:v2.2.3
Branch: feat/ssh-heartbeat
Git commit: 1272e86a337d3075427ee3a1c3681d378558d133
Built time: 2024-03-08 17:14:49
Built OS/Arch: darwin/arm64
Built Go version: go1.20.5`,
version: "unknown",
},
{
output: "hello",
version: "",
},
{
output: "",
version: "",
},
}
for _, test := range tests {
version := getDaemonVersionFromOutput([]byte(test.output))
if version != test.version {
t.Failed()
}
}
}