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

Function TestTunnelAllWorkspaceUpdatesController_DNSError

tailnet/controllers_test.go:1862–1917  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1860}
1861
1862func TestTunnelAllWorkspaceUpdatesController_DNSError(t *testing.T) {
1863 t.Parallel()
1864 ctx := testutil.Context(t, testutil.WaitShort)
1865 dnsError := xerrors.New("a bad thing happened")
1866 logger := slogtest.Make(t,
1867 &slogtest.Options{IgnoredErrorIs: []error{dnsError}}).
1868 Leveled(slog.LevelDebug)
1869
1870 fDNS := newFakeDNSSetter(ctx, t)
1871 fConn := &fakeCoordinatee{}
1872 tsc := tailnet.NewTunnelSrcCoordController(logger, fConn)
1873 uut := tailnet.NewTunnelAllWorkspaceUpdatesController(logger, tsc,
1874 tailnet.WithDNS(fDNS, "testy", tailnet.DNSNameOptions{Suffix: tailnet.CoderDNSSuffix}),
1875 )
1876
1877 updateC := newFakeWorkspaceUpdateClient(ctx, t)
1878 updateCW := uut.New(updateC)
1879
1880 w1ID := testUUID(1)
1881 w1a1ID := testUUID(1, 1)
1882 ws1a1IP := netip.MustParseAddr("fd60:627a:a42b:0101::")
1883
1884 initUp := &proto.WorkspaceUpdate{
1885 UpsertedWorkspaces: []*proto.Workspace{
1886 {Id: w1ID[:], Name: "w1"},
1887 },
1888 UpsertedAgents: []*proto.Agent{
1889 {Id: w1a1ID[:], Name: "w1a1", WorkspaceId: w1ID[:]},
1890 },
1891 }
1892 upRecvCall := testutil.TryReceive(ctx, t, updateC.recv)
1893 testutil.RequireSend(ctx, t, upRecvCall.resp, initUp)
1894
1895 expectedCoderConnectFQDN, err := dnsname.ToFQDN(
1896 fmt.Sprintf(tailnet.IsCoderConnectEnabledFmtString, tailnet.CoderDNSSuffix))
1897 require.NoError(t, err)
1898
1899 // DNS for w1a1
1900 expectedDNS := map[dnsname.FQDN][]netip.Addr{
1901 "w1a1.w1.me.coder.": {ws1a1IP},
1902 "w1a1.w1.testy.coder.": {ws1a1IP},
1903 "w1.coder.": {ws1a1IP},
1904 expectedCoderConnectFQDN: {tsaddr.CoderServiceIPv6()},
1905 }
1906 dnsCall := testutil.TryReceive(ctx, t, fDNS.calls)
1907 require.Equal(t, expectedDNS, dnsCall.hosts)
1908 testutil.RequireSend(ctx, t, dnsCall.err, dnsError)
1909
1910 // should trigger a close on the client
1911 closeCall := testutil.TryReceive(ctx, t, updateC.close)
1912 testutil.RequireSend(ctx, t, closeCall, io.EOF)
1913
1914 // error should be our initial DNS error
1915 err = testutil.TryReceive(ctx, t, updateCW.Wait())
1916 require.ErrorIs(t, err, dnsError)
1917}
1918
1919func TestTunnelAllWorkspaceUpdatesController_HandleErrors(t *testing.T) {

Callers

nothing calls this directly

Calls 13

NewMethod · 0.95
ContextFunction · 0.92
WithDNSFunction · 0.92
TryReceiveFunction · 0.92
RequireSendFunction · 0.92
newFakeDNSSetterFunction · 0.85
testUUIDFunction · 0.85
NewMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected