mirror of
https://git.vectorsigma.ru/public/k3s.git
synced 2026-08-04 05:39:27 +00:00
Generate the mock executor with mockgen and convert existing uses of the mock executor to set it up properly.
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit 0eeac6a622)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package mock
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
executor "github.com/k3s-io/k3s/pkg/daemons/executor"
|
|
)
|
|
|
|
// NewExecutorWithEmbeddedETCD creates a new mock executor, and sets it as the current executor.
|
|
// The executor exepects calls to ETCD(), and wraps the embedded executor method of the same name.
|
|
// The various ready channels are also mocked with immediate channel closure.
|
|
func NewExecutorWithEmbeddedETCD(t *testing.T) {
|
|
mockController := gomock.NewController(t)
|
|
mockExecutor := NewExecutor(mockController)
|
|
|
|
embed := &executor.Embedded{}
|
|
initialOptions := func() (executor.InitialOptions, error) {
|
|
return executor.InitialOptions{}, nil
|
|
}
|
|
closedChannel := func() <-chan struct{} {
|
|
c := make(chan struct{})
|
|
close(c)
|
|
return c
|
|
}
|
|
|
|
mockExecutor.EXPECT().ETCD(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().DoAndReturn(embed.ETCD)
|
|
mockExecutor.EXPECT().CurrentETCDOptions().AnyTimes().DoAndReturn(initialOptions)
|
|
mockExecutor.EXPECT().CRIReadyChan().AnyTimes().DoAndReturn(closedChannel)
|
|
mockExecutor.EXPECT().ETCDReadyChan().AnyTimes().DoAndReturn(closedChannel)
|
|
|
|
executor.Set(mockExecutor)
|
|
}
|