MCPcopy Index your code
hub / github.com/coder/coder / TestNewDERPMap

Function TestNewDERPMap

tailnet/derpmap_test.go:19–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestNewDERPMap(t *testing.T) {
20 t.Parallel()
21 t.Run("WithoutRemoteURL", func(t *testing.T) {
22 t.Parallel()
23 derpMap, err := tailnet.NewDERPMap(context.Background(), &tailcfg.DERPRegion{
24 RegionID: 1,
25 Nodes: []*tailcfg.DERPNode{{}},
26 }, []string{"stun.google.com:2345"}, "", "", false)
27 require.NoError(t, err)
28 require.Len(t, derpMap.Regions, 2)
29 require.Len(t, derpMap.Regions[1].Nodes, 1)
30 require.Len(t, derpMap.Regions[2].Nodes, 1)
31 })
32 t.Run("RemoteURL", func(t *testing.T) {
33 t.Parallel()
34 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
35 data, _ := json.Marshal(&tailcfg.DERPMap{
36 Regions: map[int]*tailcfg.DERPRegion{
37 1: {
38 RegionID: 1,
39 Nodes: []*tailcfg.DERPNode{{}},
40 },
41 },
42 })
43 _, _ = w.Write(data)
44 }))
45 t.Cleanup(server.Close)
46 derpMap, err := tailnet.NewDERPMap(context.Background(), &tailcfg.DERPRegion{
47 RegionID: 2,
48 }, []string{}, server.URL, "", false)
49 require.NoError(t, err)
50 require.Len(t, derpMap.Regions, 2)
51 })
52 t.Run("RemoteConflicts", func(t *testing.T) {
53 t.Parallel()
54 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
55 data, _ := json.Marshal(&tailcfg.DERPMap{
56 Regions: map[int]*tailcfg.DERPRegion{
57 1: {},
58 },
59 })
60 _, _ = w.Write(data)
61 }))
62 t.Cleanup(server.Close)
63 _, err := tailnet.NewDERPMap(context.Background(), &tailcfg.DERPRegion{
64 RegionID: 1,
65 }, []string{}, server.URL, "", false)
66 require.Error(t, err)
67 })
68 t.Run("LocalPath", func(t *testing.T) {
69 t.Parallel()
70 localPath := filepath.Join(t.TempDir(), "derp.json")
71 content, err := json.Marshal(&tailcfg.DERPMap{
72 Regions: map[int]*tailcfg.DERPRegion{
73 1: {
74 Nodes: []*tailcfg.DERPNode{{}},
75 },
76 },

Callers

nothing calls this directly

Calls 9

NewDERPMapFunction · 0.92
RunMethod · 0.65
WriteMethod · 0.65
CleanupMethod · 0.65
TempDirMethod · 0.65
WriteFileMethod · 0.65
LenMethod · 0.45
MarshalMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected