Skip to content

Commit

Permalink
update integration tests
Browse files Browse the repository at this point in the history
- Add context to all client calls
- Add additional client options
  • Loading branch information
adambkaplan committed Nov 24, 2020
1 parent 8148e51 commit ff935ee
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion test/e2e/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func printTestFailureDebugInfo(namespace string, buildRunName string) {
Follow: false,
})

podLogs, err := req.Stream()
podLogs, err := req.Stream(context.TODO())
if err != nil {
Logf("Failed to retrieve the logs of container %s: %v", container.Name, err)
continue
Expand Down
18 changes: 10 additions & 8 deletions test/integration/utils/buildruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package utils

import (
"context"

apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
Expand All @@ -18,7 +20,7 @@ import (
func (t *TestBuild) CreateBR(buildRun *v1alpha1.BuildRun) error {
brInterface := t.BuildClientSet.BuildV1alpha1().BuildRuns(t.Namespace)

_, err := brInterface.Create(buildRun)
_, err := brInterface.Create(context.TODO(), buildRun, metav1.CreateOptions{})
if err != nil {
return err
}
Expand All @@ -29,7 +31,7 @@ func (t *TestBuild) CreateBR(buildRun *v1alpha1.BuildRun) error {
func (t *TestBuild) GetBR(name string) (*v1alpha1.BuildRun, error) {
brInterface := t.BuildClientSet.BuildV1alpha1().BuildRuns(t.Namespace)

br, err := brInterface.Get(name, metav1.GetOptions{})
br, err := brInterface.Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand All @@ -40,7 +42,7 @@ func (t *TestBuild) GetBR(name string) (*v1alpha1.BuildRun, error) {
func (t *TestBuild) DeleteBR(name string) error {
brInterface := t.BuildClientSet.BuildV1alpha1().BuildRuns(t.Namespace)

if err := brInterface.Delete(name, &metav1.DeleteOptions{}); err != nil {
if err := brInterface.Delete(context.TODO(), name, metav1.DeleteOptions{}); err != nil {
return err
}

Expand All @@ -66,7 +68,7 @@ func (t *TestBuild) GetBRTillCompletion(name string) (*v1alpha1.BuildRun, error)

bInterface := t.BuildClientSet.BuildV1alpha1().BuildRuns(t.Namespace)

buildRun, err := bInterface.Get(name, metav1.GetOptions{})
buildRun, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
Expand All @@ -85,7 +87,7 @@ func (t *TestBuild) GetBRTillCompletion(name string) (*v1alpha1.BuildRun, error)
return nil, err
}

return brInterface.Get(name, metav1.GetOptions{})
return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
}

// GetBRTillStartTime returns a BuildRun that have a StartTime set.
Expand All @@ -98,7 +100,7 @@ func (t *TestBuild) GetBRTillStartTime(name string) (*v1alpha1.BuildRun, error)

bInterface := t.BuildClientSet.BuildV1alpha1().BuildRuns(t.Namespace)

buildRun, err := bInterface.Get(name, metav1.GetOptions{})
buildRun, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
}
Expand All @@ -117,7 +119,7 @@ func (t *TestBuild) GetBRTillStartTime(name string) (*v1alpha1.BuildRun, error)
return nil, err
}

return brInterface.Get(name, metav1.GetOptions{})
return brInterface.Get(context.TODO(), name, metav1.GetOptions{})
}

// GetBRTillDesiredReason polls until a BuildRun gets a particular Reason
Expand Down Expand Up @@ -156,7 +158,7 @@ func (t *TestBuild) GetBRTillDeletion(name string) (bool, error) {

bInterface := t.BuildClientSet.BuildV1alpha1().BuildRuns(t.Namespace)

_, err := bInterface.Get(name, metav1.GetOptions{})
_, err := bInterface.Get(context.TODO(), name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
return true, nil
}
Expand Down
10 changes: 6 additions & 4 deletions test/integration/utils/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package utils

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

Expand All @@ -17,15 +19,15 @@ import (
func (t *TestBuild) CreateBuild(build *v1alpha1.Build) error {
bInterface := t.BuildClientSet.BuildV1alpha1().Builds(t.Namespace)

_, err := bInterface.Create(build)
_, err := bInterface.Create(context.TODO(), build, metav1.CreateOptions{})
return err
}

// DeleteBuild deletes a Build on the desired namespace
func (t *TestBuild) DeleteBuild(name string) error {
bInterface := t.BuildClientSet.BuildV1alpha1().Builds(t.Namespace)

err := bInterface.Delete(name, &metav1.DeleteOptions{})
err := bInterface.Delete(context.TODO(), name, metav1.DeleteOptions{})

return err
}
Expand All @@ -35,7 +37,7 @@ func (t *TestBuild) GetBuild(name string) (*v1alpha1.Build, error) {
return t.BuildClientSet.
BuildV1alpha1().
Builds(t.Namespace).
Get(name, metav1.GetOptions{})
Get(context.TODO(), name, metav1.GetOptions{})
}

// PatchBuild patches an existing Build using the merge patch type
Expand All @@ -46,7 +48,7 @@ func (t *TestBuild) PatchBuild(buildName string, data []byte) (*v1alpha1.Build,
// PatchBuildWithPatchType patches an existing Build and allows specifying the patch type
func (t *TestBuild) PatchBuildWithPatchType(buildName string, data []byte, pt types.PatchType) (*v1alpha1.Build, error) {
bInterface := t.BuildClientSet.BuildV1alpha1().Builds(t.Namespace)
b, err := bInterface.Patch(buildName, pt, data)
b, err := bInterface.Patch(context.TODO(), buildName, pt, data, metav1.PatchOptions{})
if err != nil {
return nil, err
}
Expand Down
10 changes: 8 additions & 2 deletions test/integration/utils/buildstrategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

package utils

import "github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
)

// This class is intended to host all CRUD calls for testing BuildStrategy CRDs resources

// CreateBuildStrategy generates a BuildStrategy on the current test namespace
func (t *TestBuild) CreateBuildStrategy(bs *v1alpha1.BuildStrategy) error {
bsInterface := t.BuildClientSet.BuildV1alpha1().BuildStrategies(t.Namespace)

_, err := bsInterface.Create(bs)
_, err := bsInterface.Create(context.TODO(), bs, metav1.CreateOptions{})
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions test/integration/utils/clusterbuildstrategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package utils

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
Expand All @@ -16,7 +18,7 @@ import (
func (t *TestBuild) CreateClusterBuildStrategy(cbs *v1alpha1.ClusterBuildStrategy) error {
cbsInterface := t.BuildClientSet.BuildV1alpha1().ClusterBuildStrategies()

_, err := cbsInterface.Create(cbs)
_, err := cbsInterface.Create(context.TODO(), cbs, metav1.CreateOptions{})
if err != nil {
return err
}
Expand All @@ -27,7 +29,7 @@ func (t *TestBuild) CreateClusterBuildStrategy(cbs *v1alpha1.ClusterBuildStrateg
func (t *TestBuild) DeleteClusterBuildStrategy(name string) error {
cbsInterface := t.BuildClientSet.BuildV1alpha1().ClusterBuildStrategies()

err := cbsInterface.Delete(name, &metav1.DeleteOptions{})
err := cbsInterface.Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions test/integration/utils/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package utils

import (
"context"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -19,7 +21,7 @@ func (t *TestBuild) CreateNamespace() error {
Name: t.Namespace,
},
}
_, err := client.Create(ns)
_, err := client.Create(context.TODO(), ns, metav1.CreateOptions{})
if err != nil {
return err
}
Expand All @@ -31,7 +33,7 @@ func (t *TestBuild) DeleteNamespaces(nsList []string) error {
client := t.Clientset.CoreV1().Namespaces()

for _, ns := range nsList {
err := client.Delete(ns, &metav1.DeleteOptions{})
err := client.Delete(context.TODO(), ns, metav1.DeleteOptions{})
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion test/integration/utils/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
package utils

import (
"context"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// This class is intended to host all CRUD calls for testing secrets primitive resources

// CreateSecret generates a Secret on the current test namespace
func (t *TestBuild) CreateSecret(ns string, secret *corev1.Secret) error {
client := t.Clientset.CoreV1().Secrets(ns)
_, err := client.Create(secret)
_, err := client.Create(context.TODO(), secret, metav1.CreateOptions{})
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions test/integration/utils/service_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package utils

import (
"context"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -16,25 +18,25 @@ import (
// CreateSAFromName creates a simple ServiceAccount with the provided name if it does not exist.
func (t *TestBuild) CreateSAFromName(saName string) error {
client := t.Clientset.CoreV1().ServiceAccounts(t.Namespace)
_, err := client.Get(saName, metav1.GetOptions{})
_, err := client.Get(context.TODO(), saName, metav1.GetOptions{})
// If the service account already exists, no error is returned
if err == nil {
return nil
}
if !apierrors.IsNotFound(err) {
return err
}
_, err = client.Create(&corev1.ServiceAccount{
_, err = client.Create(context.TODO(), &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: saName,
}})
}}, metav1.CreateOptions{})
return err
}

// GetSA retrieves an existing service-account by name
func (t *TestBuild) GetSA(saName string) (*v1.ServiceAccount, error) {
client := t.Clientset.CoreV1().ServiceAccounts(t.Namespace)
sa, err := client.Get(saName, metav1.GetOptions{})
sa, err := client.Get(context.TODO(), saName, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ff935ee

Please sign in to comment.