2023-06-21 14:33:19 -05:00
|
|
|
package cli_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
2023-08-18 13:55:43 -05:00
|
|
|
"github.com/coder/coder/v2/cli/clitest"
|
2024-03-26 12:44:31 -05:00
|
|
|
"github.com/coder/coder/v2/codersdk/healthsdk"
|
2023-08-18 13:55:43 -05:00
|
|
|
"github.com/coder/coder/v2/pty/ptytest"
|
2023-06-21 14:33:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestNetcheck(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
pty := ptytest.New(t)
|
|
|
|
|
config := login(t, pty)
|
|
|
|
|
|
|
|
|
|
var out bytes.Buffer
|
|
|
|
|
inv, _ := clitest.New(t, "netcheck", "--global-config", string(config))
|
|
|
|
|
inv.Stdout = &out
|
|
|
|
|
|
|
|
|
|
clitest.StartWithWaiter(t, inv).RequireSuccess()
|
|
|
|
|
|
2023-06-22 08:02:05 +10:00
|
|
|
b := out.Bytes()
|
|
|
|
|
t.Log(string(b))
|
2024-06-13 10:19:36 +04:00
|
|
|
var report healthsdk.ClientNetcheckReport
|
2023-06-22 08:02:05 +10:00
|
|
|
require.NoError(t, json.Unmarshal(b, &report))
|
2023-06-21 14:33:19 -05:00
|
|
|
|
2024-06-07 10:01:54 +01:00
|
|
|
// We do not assert that the report is healthy, just that
|
|
|
|
|
// it has the expected number of reports per region.
|
2024-06-13 10:19:36 +04:00
|
|
|
require.Len(t, report.DERP.Regions, 1+1) // 1 built-in region + 1 test-managed STUN region
|
|
|
|
|
for _, v := range report.DERP.Regions {
|
2023-06-22 08:02:05 +10:00
|
|
|
require.Len(t, v.NodeReports, len(v.Region.Nodes))
|
|
|
|
|
}
|
2023-06-21 14:33:19 -05:00
|
|
|
}
|