MCPcopy
hub / github.com/fatedier/frp / TestRunStopsStartedComponentsOnInitialLoginFailure

Function TestRunStopsStartedComponentsOnInitialLoginFailure

client/service_test.go:46–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestRunStopsStartedComponentsOnInitialLoginFailure(t *testing.T) {
47 port := getFreeTCPPort(t)
48 agg := source.NewAggregator(source.NewConfigSource())
49
50 svr, err := NewService(ServiceOptions{
51 Common: &v1.ClientCommonConfig{
52 LoginFailExit: lo.ToPtr(true),
53 WebServer: v1.WebServerConfig{
54 Addr: "127.0.0.1",
55 Port: port,
56 },
57 },
58 ConfigSourceAggregator: agg,
59 ConnectorCreator: func(context.Context, *v1.ClientCommonConfig) Connector {
60 return &failingConnector{err: errors.New("login boom")}
61 },
62 })
63 if err != nil {
64 t.Fatalf("new service: %v", err)
65 }
66
67 err = svr.Run(context.Background())
68 if err == nil {
69 t.Fatal("expected run error, got nil")
70 }
71 if !strings.Contains(err.Error(), "login boom") {
72 t.Fatalf("unexpected error: %v", err)
73 }
74 if svr.webServer != nil {
75 t.Fatal("expected web server to be cleaned up after initial login failure")
76 }
77
78 ln, err := net.Listen("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(port)))
79 if err != nil {
80 t.Fatalf("expected admin port to be released: %v", err)
81 }
82 _ = ln.Close()
83}
84
85func TestNewServiceDoesNotLeakAdminListenerOnAuthBuildFailure(t *testing.T) {
86 port := getFreeTCPPort(t)

Callers

nothing calls this directly

Calls 8

RunMethod · 0.95
NewAggregatorFunction · 0.92
NewConfigSourceFunction · 0.92
getFreeTCPPortFunction · 0.85
NewServiceFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45
ListenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…