Skip to content

Commit ed8daee

Browse files
authored
Merge pull request #736 from chmouel/some-wait-test
2 parents d45cf72 + 4d9e658 commit ed8daee

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kubeinteraction
2+
3+
import (
4+
"testing"
5+
6+
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
7+
"gotest.tools/v3/assert"
8+
)
9+
10+
func TestNewKubernetesInteraction(t *testing.T) {
11+
_, err := NewKubernetesInteraction(params.New())
12+
assert.NilError(t, err)
13+
}

pkg/kubeinteraction/wait_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package kubeinteraction
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
"time"
7+
8+
rtesting "knative.dev/pkg/reconciler/testing"
9+
)
10+
11+
func TestPollImmediateWithContext(t *testing.T) {
12+
tests := []struct {
13+
name string
14+
wantErr bool
15+
fn func() (bool, error)
16+
}{
17+
{
18+
name: "test true",
19+
fn: func() (bool, error) {
20+
return true, nil
21+
},
22+
},
23+
{
24+
name: "test false",
25+
fn: func() (bool, error) {
26+
return true, fmt.Errorf("error me")
27+
},
28+
wantErr: true,
29+
},
30+
{
31+
name: "timeout",
32+
fn: func() (bool, error) {
33+
return false, nil
34+
},
35+
wantErr: true,
36+
},
37+
}
38+
for _, tt := range tests {
39+
t.Run(tt.name, func(t *testing.T) {
40+
ctx, _ := rtesting.SetupFakeContext(t)
41+
if err := PollImmediateWithContext(ctx, 1*time.Millisecond, tt.fn); (err != nil) != tt.wantErr {
42+
t.Errorf("PollImmediateWithContext() error = %v, wantErr %v", err, tt.wantErr)
43+
}
44+
})
45+
}
46+
}

0 commit comments

Comments
 (0)