Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Move test/clients.go to test/clients_test.go - solves the Resolver bi…
Browse files Browse the repository at this point in the history
…naries issue

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
abayer committed May 23, 2022
1 parent 666b136 commit 6721eae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@
limitations under the License.
*/

package testing
package framework

import (
"context"
"strings"
"testing"
"time"

"github.com/tektoncd/resolution/pkg/resolver/framework"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/tektoncd/resolution/pkg/apis/resolution/v1alpha1"
ttesting "github.com/tektoncd/resolution/pkg/reconciler/testing"
"github.com/tektoncd/resolution/test"
"github.com/tektoncd/resolution/test/diff"
"github.com/tektoncd/resolution/test/names"
Expand All @@ -53,11 +50,11 @@ var (
// ResolutionRequestStatus and error, both of which can be nil. It instantiates a controller for that resolver and
// reconciles the given request. It then checks for the expected error, if any, and compares the resulting status with
// the expected status.
func RunResolverReconcileTest(t *testing.T, d test.Data, resolver framework.Resolver, request *v1alpha1.ResolutionRequest,
func RunResolverReconcileTest(ctx context.Context, t *testing.T, d test.Data, resolver Resolver, request *v1alpha1.ResolutionRequest,
expectedStatus *v1alpha1.ResolutionRequestStatus, expectedErr error) {
t.Helper()

testAssets, cancel := GetResolverFrameworkController(t, d, resolver, setClockOnReconciler)
testAssets, cancel := GetResolverFrameworkController(ctx, t, d, resolver, setClockOnReconciler)
defer cancel()

err := testAssets.Controller.Reconciler.Reconcile(testAssets.Ctx, getRequestName(request))
Expand Down Expand Up @@ -89,18 +86,17 @@ func RunResolverReconcileTest(t *testing.T, d test.Data, resolver framework.Reso

// GetResolverFrameworkController returns an instance of the resolver framework controller/reconciler using the given resolver,
// seeded with d, where d represents the state of the system (existing resources) needed for the test.
func GetResolverFrameworkController(t *testing.T, d test.Data, resolver framework.Resolver, modifiers ...framework.ReconcilerModifier) (test.Assets, func()) {
func GetResolverFrameworkController(ctx context.Context, t *testing.T, d test.Data, resolver Resolver, modifiers ...ReconcilerModifier) (test.Assets, func()) {
t.Helper()
names.TestingSeed()
return initializeResolverFrameworkControllerAssets(t, d, resolver, modifiers...)
return initializeResolverFrameworkControllerAssets(ctx, t, d, resolver, modifiers...)
}

func initializeResolverFrameworkControllerAssets(t *testing.T, d test.Data, resolver framework.Resolver, modifiers ...framework.ReconcilerModifier) (test.Assets, func()) {
ctx, _ := ttesting.SetupFakeContext(t)
func initializeResolverFrameworkControllerAssets(ctx context.Context, t *testing.T, d test.Data, resolver Resolver, modifiers ...ReconcilerModifier) (test.Assets, func()) {
ctx, cancel := context.WithCancel(ctx)
c, informers := test.SeedTestData(t, ctx, d)
configMapWatcher := cminformer.NewInformedWatcher(c.Kube, system.Namespace())
ctl := framework.NewController(ctx, resolver, modifiers...)(ctx, configMapWatcher)
ctl := NewController(ctx, resolver, modifiers...)(ctx, configMapWatcher)
if err := configMapWatcher.Start(ctx.Done()); err != nil {
t.Fatalf("error starting configmap watcher: %v", err)
}
Expand All @@ -123,7 +119,7 @@ func getRequestName(rr *v1alpha1.ResolutionRequest) string {
return strings.Join([]string{rr.Namespace, rr.Name}, "/")
}

func setClockOnReconciler(r *framework.Reconciler) {
func setClockOnReconciler(r *Reconciler) {
if r.Clock == nil {
r.Clock = testClock
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package testing
package framework

import (
"context"
Expand All @@ -23,8 +23,6 @@ import (
"strings"
"time"

"github.com/tektoncd/resolution/pkg/resolver/framework"

resolutioncommon "github.com/tektoncd/resolution/pkg/common"
)

Expand All @@ -41,7 +39,7 @@ const (
FakeParamName string = "fake-key"
)

var _ framework.Resolver = &FakeResolver{}
var _ Resolver = &FakeResolver{}

// FakeResolvedResource is a framework.ResolvedResource implementation for use with the fake resolver.
// If it's the value in the FakeResolver's ForParam map for the key given as the fake param value, the FakeResolver will
Expand Down Expand Up @@ -120,7 +118,7 @@ func (r *FakeResolver) ValidateParams(_ context.Context, params map[string]strin

// Resolve performs the work of fetching a file from the fake resolver given a map of
// parameters.
func (r *FakeResolver) Resolve(_ context.Context, params map[string]string) (framework.ResolvedResource, error) {
func (r *FakeResolver) Resolve(_ context.Context, params map[string]string) (ResolvedResource, error) {
paramValue := params[FakeParamName]

frr, ok := r.ForParam[paramValue]
Expand All @@ -139,7 +137,7 @@ func (r *FakeResolver) Resolve(_ context.Context, params map[string]string) (fra
return frr, nil
}

var _ framework.TimedResolution = &FakeResolver{}
var _ TimedResolution = &FakeResolver{}

// GetResolutionTimeout returns the configured timeout for the reconciler, or the default time.Duration if not configured.
func (r *FakeResolver) GetResolutionTimeout(ctx context.Context, defaultTimeout time.Duration) time.Duration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

package testing
package framework

import (
"encoding/base64"
Expand All @@ -24,9 +24,11 @@ import (

"github.com/tektoncd/resolution/pkg/apis/resolution/v1alpha1"
resolutioncommon "github.com/tektoncd/resolution/pkg/common"
ttesting "github.com/tektoncd/resolution/pkg/reconciler/testing"
"github.com/tektoncd/resolution/test"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"

_ "knative.dev/pkg/system/testing" // Setup system.Namespace()
)

Expand Down Expand Up @@ -171,7 +173,8 @@ func TestReconcile(t *testing.T) {
fakeResolver.Timeout = tc.reconcilerTimeout
}

RunResolverReconcileTest(t, d, fakeResolver, tc.inputRequest, tc.expectedStatus, tc.expectedErr)
ctx, _ := ttesting.SetupFakeContext(t)
RunResolverReconcileTest(ctx, t, d, fakeResolver, tc.inputRequest, tc.expectedStatus, tc.expectedErr)
})
}
}
File renamed without changes.

0 comments on commit 6721eae

Please sign in to comment.