mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-23 03:17:43 +00:00
ipn/ipnlocal: make GetExt work earlier, before extension init
Taildrop wasn't working on iOS since #15971 because GetExt didn't work until after init, but that PR moved Init until after Start. This makes GetExt work before LocalBackend.Start (ExtensionHost.Init). Updates #15812 Change-Id: I6e87257cd97a20f86083a746d39df223e5b6791b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
54970054a6
commit
30a89ad378
@@ -30,6 +30,7 @@ import (
|
||||
"tailscale.com/tstime"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/lazy"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/persist"
|
||||
"tailscale.com/util/must"
|
||||
)
|
||||
@@ -1042,6 +1043,38 @@ func TestNilExtensionHostMethodCall(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// extBeforeStartExtension is a test extension used by TestGetExtBeforeStart.
|
||||
// It is registered with the [ipnext.RegisterExtension].
|
||||
type extBeforeStartExtension struct{}
|
||||
|
||||
func init() {
|
||||
ipnext.RegisterExtension("ext-before-start", mkExtBeforeStartExtension)
|
||||
}
|
||||
|
||||
func mkExtBeforeStartExtension(logger.Logf, ipnext.SafeBackend) (ipnext.Extension, error) {
|
||||
return extBeforeStartExtension{}, nil
|
||||
}
|
||||
|
||||
func (extBeforeStartExtension) Name() string { return "ext-before-start" }
|
||||
func (extBeforeStartExtension) Init(ipnext.Host) error {
|
||||
return nil
|
||||
}
|
||||
func (extBeforeStartExtension) Shutdown() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestGetExtBeforeStart verifies that an extension registered via
|
||||
// RegisterExtension can be retrieved with GetExt before the host is started
|
||||
// (via LocalBackend.Start)
|
||||
func TestGetExtBeforeStart(t *testing.T) {
|
||||
lb := newTestBackend(t)
|
||||
// Now call GetExt without calling Start on the LocalBackend.
|
||||
_, ok := GetExt[extBeforeStartExtension](lb)
|
||||
if !ok {
|
||||
t.Fatal("didn't find extension")
|
||||
}
|
||||
}
|
||||
|
||||
// checkMethodCallWithZeroArgs calls the method m on the receiver r
|
||||
// with zero values for all its arguments, except the receiver itself.
|
||||
// It returns the result of the method call, or fails the test if the call panics.
|
||||
@@ -1151,6 +1184,10 @@ type testExtension struct {
|
||||
|
||||
var _ ipnext.Extension = (*testExtension)(nil)
|
||||
|
||||
// PermitDoubleRegister is a sentinel method whose existence tells the
|
||||
// ExtensionHost to permit it to be registered multiple times.
|
||||
func (*testExtension) PermitDoubleRegister() {}
|
||||
|
||||
func (e *testExtension) setT(t *testing.T) {
|
||||
e.t = t
|
||||
}
|
||||
|
Reference in New Issue
Block a user