mirror of
https://github.com/k3s-io/k3s.git
synced 2026-06-10 09:22:37 -04:00
Fix etcd tests to use mock executor
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
parent
a8bc412422
commit
72bbd676f1
3 changed files with 86 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
80
tests/mock/executor.go
Normal file
80
tests/mock/executor.go
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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/<RANDOM_STRING>/".
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue