diff --git a/pkg/etcd/etcd_linux_test.go b/pkg/etcd/etcd_linux_test.go index 12bc4192a71..4fab77b2547 100644 --- a/pkg/etcd/etcd_linux_test.go +++ b/pkg/etcd/etcd_linux_test.go @@ -399,11 +399,10 @@ func Test_UnitETCD_Start(t *testing.T) { } if err := tt.setup(e, &tt.fields.context); err != nil { - t.Errorf("Setup for ETCD.Start() failed = %v", err) - return + t.Fatalf("Setup for ETCD.Start() failed = %v", err) } if err := e.Start(tt.fields.context.ctx, tt.args.clientAccessInfo); (err != nil) != tt.wantErr { - t.Errorf("ETCD.Start() error = %v, wantErr %v", err, tt.wantErr) + t.Fatalf("ETCD.Start() error = %v, wantErr %v", err, tt.wantErr) } if !tt.wantErr { memberAddr = e.address diff --git a/tests/mock/executor.go b/tests/mock/executor.go new file mode 100644 index 00000000000..7f8c7587e22 --- /dev/null +++ b/tests/mock/executor.go @@ -0,0 +1,80 @@ +package mock + +import ( + "context" + "errors" + "net/http" + + "github.com/k3s-io/k3s/pkg/cli/cmds" + "github.com/k3s-io/k3s/pkg/daemons/config" + "github.com/k3s-io/k3s/pkg/daemons/executor" + "k8s.io/apiserver/pkg/authentication/authenticator" +) + +// mock executor that does not actually start anything +type Executor struct{} + +func (e *Executor) Bootstrap(ctx context.Context, nodeConfig *config.Node, cfg cmds.Agent) error { + return errors.New("not implemented") +} + +func (e *Executor) Kubelet(ctx context.Context, args []string) error { + return errors.New("not implemented") +} + +func (e *Executor) KubeProxy(ctx context.Context, args []string) error { + return errors.New("not implemented") +} + +func (e *Executor) APIServerHandlers(ctx context.Context) (authenticator.Request, http.Handler, error) { + return nil, nil, errors.New("not implemented") +} + +func (e *Executor) APIServer(ctx context.Context, etcdReady <-chan struct{}, args []string) error { + return errors.New("not implemented") +} + +func (e *Executor) Scheduler(ctx context.Context, nodeReady <-chan struct{}, args []string) error { + return errors.New("not implemented") +} + +func (e *Executor) ControllerManager(ctx context.Context, args []string) error { + return errors.New("not implemented") +} + +func (e *Executor) CurrentETCDOptions() (executor.InitialOptions, error) { + return executor.InitialOptions{}, nil +} + +func (e *Executor) ETCD(ctx context.Context, args executor.ETCDConfig, extraArgs []string) error { + embed := &executor.Embedded{} + return embed.ETCD(ctx, args, extraArgs) +} + +func (e *Executor) CloudControllerManager(ctx context.Context, ccmRBACReady <-chan struct{}, args []string) error { + return errors.New("not implemented") +} + +func (e *Executor) Containerd(ctx context.Context, node *config.Node) error { + return errors.New("not implemented") +} + +func (e *Executor) Docker(ctx context.Context, node *config.Node) error { + return errors.New("not implemented") +} + +func (e *Executor) CRI(ctx context.Context, node *config.Node) error { + return errors.New("not implemented") +} + +func (e *Executor) APIServerReadyChan() <-chan struct{} { + c := make(chan struct{}) + close(c) + return c +} + +func (e *Executor) CRIReadyChan() <-chan struct{} { + c := make(chan struct{}) + close(c) + return c +} diff --git a/tests/unit.go b/tests/unit.go index d385815ccc6..7f94c42be94 100644 --- a/tests/unit.go +++ b/tests/unit.go @@ -7,6 +7,7 @@ import ( "github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/daemons/control/deps" + "github.com/k3s-io/k3s/pkg/daemons/executor" ) // GenerateDataDir creates a temporary directory at "/tmp/k3s//". @@ -43,6 +44,9 @@ func CleanupDataDir(cnf *config.Control) { // GenerateRuntime creates a temporary data dir and configures // config.ControlRuntime with all the appropriate certificate keys. func GenerateRuntime(cnf *config.Control) error { + // use mock executor that does not actually start things + executor.Set(&mock.Executor{}) + // reuse ready channel from existing runtime if set cnf.Runtime = config.NewRuntime() if err := GenerateDataDir(cnf); err != nil {