mirror of https://github.com/knative/client.git
Adding tests for wait pkg (#1371)
This commit is contained in:
parent
dfc8665d12
commit
a7265a435e
|
|
@ -15,6 +15,7 @@
|
||||||
package wait
|
package wait
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -84,6 +85,19 @@ type testCase struct {
|
||||||
watchResults []watch.Event
|
watchResults []watch.Event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewWatcherWithVersion(t *testing.T) {
|
||||||
|
w, err := NewWatcherWithVersion(context.Background(), watchF(func(context.Context, metav1.ListOptions) (watch.Interface, error) {
|
||||||
|
return NewFakeWatch([]watch.Event{}), nil
|
||||||
|
}), nil, "mockNamespace", "resourceName", "mockName", "v1", 5*time.Second)
|
||||||
|
w.Stop()
|
||||||
|
assert.NilError(t, err)
|
||||||
|
w, err = NewWatcherWithVersion(context.Background(), watchF(func(context.Context, metav1.ListOptions) (watch.Interface, error) {
|
||||||
|
return NewFakeWatch([]watch.Event{}), fmt.Errorf("mockErrMsg")
|
||||||
|
}), nil, "mockNamespace", "resourceName", "mockName", "v1", 5*time.Second)
|
||||||
|
w.Stop()
|
||||||
|
assert.NilError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestPollWatcher(t *testing.T) {
|
func TestPollWatcher(t *testing.T) {
|
||||||
cases := []testCase{
|
cases := []testCase{
|
||||||
// Doesn't exist for a while, then does for a while.
|
// Doesn't exist for a while, then does for a while.
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
package wait
|
package wait
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -26,6 +27,7 @@ import (
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
|
"knative.dev/client/pkg/util"
|
||||||
"knative.dev/pkg/apis"
|
"knative.dev/pkg/apis"
|
||||||
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
|
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
|
||||||
)
|
)
|
||||||
|
|
@ -73,7 +75,8 @@ func TestWaitCancellation(t *testing.T) {
|
||||||
func(obj runtime.Object) (apis.Conditions, error) {
|
func(obj runtime.Object) (apis.Conditions, error) {
|
||||||
return apis.Conditions(obj.(*servingv1.Service).Status.Conditions), nil
|
return apis.Conditions(obj.(*servingv1.Service).Status.Conditions), nil
|
||||||
})
|
})
|
||||||
err, _ = wfr.Wait(ctx, "foobar", "", Options{Timeout: &timeout}, NoopMessageCallback())
|
window := 2 * time.Second
|
||||||
|
err, _ = wfr.Wait(ctx, "foobar", "", Options{Timeout: nil, ErrorWindow: &window}, NoopMessageCallback())
|
||||||
assert.Assert(t, errors.Is(err, context.Canceled))
|
assert.Assert(t, errors.Is(err, context.Canceled))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,6 +256,15 @@ func TestAddWaitForDelete(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSimpleMessageCallback(t *testing.T) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
callback := SimpleMessageCallback(&out)
|
||||||
|
callback(5*time.Second, "hello")
|
||||||
|
assert.Assert(t, util.ContainsAll(out.String(), "hello"))
|
||||||
|
callback(5*time.Second, "hello")
|
||||||
|
assert.Assert(t, util.ContainsAll(out.String(), "..."))
|
||||||
|
}
|
||||||
|
|
||||||
// Test cases which consists of a series of events to send and the expected behaviour.
|
// Test cases which consists of a series of events to send and the expected behaviour.
|
||||||
func prepareTestCases(name string) []waitForReadyTestCase {
|
func prepareTestCases(name string) []waitForReadyTestCase {
|
||||||
return []waitForReadyTestCase{
|
return []waitForReadyTestCase{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue