diff --git a/go.mod b/go.mod index f4316e54..fad53ff4 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/docker/docker v20.10.21+incompatible github.com/docker/go-units v0.5.0 github.com/gin-gonic/gin v1.8.1 - github.com/go-vela/sdk-go v0.16.1 - github.com/go-vela/server v0.16.1 - github.com/go-vela/types v0.16.1 + github.com/go-vela/sdk-go v0.16.2 + github.com/go-vela/server v0.16.2 + github.com/go-vela/types v0.16.2 github.com/google/go-cmp v0.5.9 github.com/joho/godotenv v1.4.0 github.com/opencontainers/image-spec v1.0.2 diff --git a/go.sum b/go.sum index 41bbe5dc..13158bb2 100644 --- a/go.sum +++ b/go.sum @@ -153,12 +153,12 @@ github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXS github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-vela/sdk-go v0.16.1 h1:TrexXFMRQVs5UQXL9NV0Urv+sRu7RElKyVo8qK/yGLY= -github.com/go-vela/sdk-go v0.16.1/go.mod h1:fm8xpL9t1pBLdB9cQDHn8jyuQX8IapYzexD/cbQwKoc= -github.com/go-vela/server v0.16.1 h1:1ihfbBha098noeM9dbBNSVqj8PLaNy+Sw9VBtc7tabY= -github.com/go-vela/server v0.16.1/go.mod h1:vqSBrSJWw/OpynddskXDS5GggmlYpisQXODEWsGXk6k= -github.com/go-vela/types v0.16.1 h1:PGtOQ0AQLAFJ23wi6ns5JF1y68v4VjA/NbZs5HYZmhY= -github.com/go-vela/types v0.16.1/go.mod h1:6KoRkvXMw9DkAcLdtI7PxPqMlT2Bl0DiigQamLGGjwo= +github.com/go-vela/sdk-go v0.16.2 h1:M9+u89mGomJc2uwUPVGWp9UnUIFm0IhIIsFEfxROhZQ= +github.com/go-vela/sdk-go v0.16.2/go.mod h1:BuTkw+MYWbAKJ6+ZtQ/nNmwIcjn/tysCPks4X+csBGE= +github.com/go-vela/server v0.16.2 h1:qovjGN9ZQazjV0JTXzP6o5UPSs1D+wyUMpbG4G6aXZI= +github.com/go-vela/server v0.16.2/go.mod h1:bf9dpkzhL2T6G6fxIwjmMjzoD+e5Xfmg3DcckP6lqHc= +github.com/go-vela/types v0.16.2 h1:c2Kkj7OKv4sjPrsOBbnPSQqfsNpOFM2La7LfP+81EF0= +github.com/go-vela/types v0.16.2/go.mod h1:6KoRkvXMw9DkAcLdtI7PxPqMlT2Bl0DiigQamLGGjwo= github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= diff --git a/runtime/kubernetes/build_test.go b/runtime/kubernetes/build_test.go index 50f304ea..d8722c7b 100644 --- a/runtime/kubernetes/build_test.go +++ b/runtime/kubernetes/build_test.go @@ -431,7 +431,7 @@ func TestKubernetes_StreamBuild(t *testing.T) { cancel() } else if test.doReady { // simulate AssembleBuild - close(_engine.PodTracker.Ready) + _engine.MarkPodTrackerReady() } }() diff --git a/runtime/kubernetes/container_test.go b/runtime/kubernetes/container_test.go index cb190171..9383491f 100644 --- a/runtime/kubernetes/container_test.go +++ b/runtime/kubernetes/container_test.go @@ -517,11 +517,8 @@ func TestKubernetes_WaitContainer(t *testing.T) { } go func() { - oldPod := test.oldPod.DeepCopy() - oldPod.SetResourceVersion("older") - // simulate a re-sync/PodUpdate event - _engine.PodTracker.HandlePodUpdate(oldPod, _engine.Pod) + _engine.SimulateResync(test.oldPod) }() err = _engine.WaitContainer(context.Background(), test.container) diff --git a/runtime/kubernetes/mock.go b/runtime/kubernetes/mock.go index 602dde07..b409a157 100644 --- a/runtime/kubernetes/mock.go +++ b/runtime/kubernetes/mock.go @@ -85,3 +85,34 @@ func NewMock(_pod *v1.Pod, opts ...ClientOpt) (*client, error) { return c, nil } + +// MockKubernetesRuntime makes it possible to use the client mocks in other packages. +// +// This interface is intended for running tests only. +type MockKubernetesRuntime interface { + MarkPodTrackerReady() + SimulateResync(*v1.Pod) +} + +// MarkPodTrackerReady signals that PodTracker has been setup with ContainerTrackers. +// +// This function is intended for running tests only. +func (c *client) MarkPodTrackerReady() { + close(c.PodTracker.Ready) +} + +// SimulateResync simulates an resync where the PodTracker refreshes its cache. +// This resync is from oldPod to runtime.Pod. If nil, oldPod defaults to runtime.Pod. +// +// This function is intended for running tests only. +func (c *client) SimulateResync(oldPod *v1.Pod) { + if oldPod == nil { + oldPod = c.Pod + } + + oldPod = oldPod.DeepCopy() + oldPod.SetResourceVersion("older") + + // simulate a re-sync/PodUpdate event + c.PodTracker.HandlePodUpdate(oldPod, c.Pod) +}