mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
Upstream changes include: - Add get/set db version commands (#3579) - Fix link dial race condition (#3566) - Update channel version to v4.3.5 - Retire ingress-nginx in favor of Traefik (#3582) - Appease golangci-lint (#3594) - Fix flaky certchecker and link tests - Enable verbose logging for Go SDK apps - Improve router quickstart crash recovery Conflicts resolved keeping hanzozt branding while incorporating all upstream code improvements.
132 lines
3.5 KiB
Go
132 lines
3.5 KiB
Go
/*
|
|
(c) Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package tests
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/hanzozt/fablab/kernel/model"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestScp(t *testing.T) {
|
|
allZetHostedFailed := true
|
|
allZetClientsFailed := true
|
|
|
|
waitForTerminators(t, 30*time.Second,
|
|
"ert-ssh", "ert-ssh-unencrypted",
|
|
"zet-ssh", "zet-ssh-unencrypted",
|
|
"zt-tunnel-ssh", "zt-tunnel-ssh-unencrypted")
|
|
|
|
t.Run("scp-tests", func(t *testing.T) {
|
|
t.Run("test-ert-scp", func(t *testing.T) {
|
|
t.Parallel()
|
|
for _, hostType := range []string{"ert", "zet", "zt-tunnel"} {
|
|
for _, encrypted := range []bool{true, false} {
|
|
success := testScp(t, "ert", hostType, encrypted)
|
|
if hostType == "zet" && success {
|
|
allZetHostedFailed = false
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("test-zet-scp", func(t *testing.T) {
|
|
t.Parallel()
|
|
for _, hostType := range []string{"zet", "zt-tunnel", "ert"} {
|
|
for _, encrypted := range []bool{true, false} {
|
|
success := testScp(t, "zet", hostType, encrypted)
|
|
if hostType == "zet" && success {
|
|
allZetHostedFailed = false
|
|
}
|
|
if success {
|
|
allZetClientsFailed = false
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
t.Run("test-zt-tunnel-scp", func(t *testing.T) {
|
|
t.Parallel()
|
|
for _, hostType := range []string{"zt-tunnel", "ert", "zet"} {
|
|
for _, encrypted := range []bool{true, false} {
|
|
success := testScp(t, "zt-tunnel", hostType, encrypted)
|
|
if hostType == "zet" && success {
|
|
allZetHostedFailed = false
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
req := require.New(t)
|
|
req.False(allZetHostedFailed, "all zet hosted file transfer should not failed, indicates bigger issue")
|
|
req.False(allZetClientsFailed, "all zet client file transfers should not failed, indicates bigger issue")
|
|
}
|
|
|
|
func testScp(t *testing.T, hostSelector string, hostType string, encrypted bool) bool {
|
|
encDesk := "encrypted"
|
|
if !encrypted {
|
|
encDesk = "unencrypted"
|
|
}
|
|
|
|
success := true
|
|
|
|
nameExtra := ""
|
|
if !encrypted {
|
|
nameExtra = "-unencrypted"
|
|
}
|
|
|
|
tests := []struct {
|
|
direction string
|
|
cmd string
|
|
}{
|
|
{
|
|
direction: "<-",
|
|
cmd: fmt.Sprintf("scp -o StrictHostKeyChecking=no scp://ssh-%s%s.zt:2022/fablab/bin/zt /tmp/zt-%s", hostType, nameExtra, uuid.NewString()),
|
|
}, {
|
|
direction: "->",
|
|
cmd: fmt.Sprintf("scp -o StrictHostKeyChecking=no ./fablab/bin/zt scp://ssh-%s%s.zt:2022//tmp/zt-%s", hostType, nameExtra, uuid.NewString()),
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(fmt.Sprintf("(%s%s%s)-%v", hostSelector, test.direction, hostType, encDesk), func(t *testing.T) {
|
|
success = false
|
|
host, err := model.GetModel().SelectHost("." + hostSelector + "-client")
|
|
req := require.New(t)
|
|
req.NoError(err)
|
|
|
|
o, err := host.ExecLoggedWithTimeout(50*time.Second, test.cmd)
|
|
if hostType == "zet" && err != nil {
|
|
t.Skipf("zet hosted ssh failed [%v]", err.Error())
|
|
} else if hostSelector == "zet" && err != nil {
|
|
t.Skipf("zet client ssh failed [%v]", err.Error())
|
|
} else {
|
|
t.Log(o)
|
|
req.NoError(err)
|
|
success = true
|
|
}
|
|
})
|
|
}
|
|
|
|
return success
|
|
}
|