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

Commit

Permalink
TODO: The resolver testing framework ended up breaking the actual res…
Browse files Browse the repository at this point in the history
…ovlers thanks to Knative testing magic.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
abayer committed May 19, 2022
1 parent 031ee33 commit 653919d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
limitations under the License.
*/

package framework
package testing

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"
Expand Down Expand Up @@ -51,7 +53,7 @@ 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 Resolver, request *v1alpha1.ResolutionRequest,
func RunResolverReconcileTest(t *testing.T, d test.Data, resolver framework.Resolver, request *v1alpha1.ResolutionRequest,
expectedStatus *v1alpha1.ResolutionRequestStatus, expectedErr error) {
t.Helper()

Expand Down Expand Up @@ -87,18 +89,18 @@ func RunResolverReconcileTest(t *testing.T, d test.Data, resolver Resolver, requ

// 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 Resolver, modifiers ...ReconcilerModifier) (test.Assets, func()) {
func GetResolverFrameworkController(t *testing.T, d test.Data, resolver framework.Resolver, modifiers ...framework.ReconcilerModifier) (test.Assets, func()) {
t.Helper()
names.TestingSeed()
return initializeResolverFrameworkControllerAssets(t, d, resolver, modifiers...)
}

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

func setClockOnReconciler(r *Reconciler) {
func setClockOnReconciler(r *framework.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 framework
package testing

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

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

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

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

var _ Resolver = &FakeResolver{}
var _ framework.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 @@ -118,7 +120,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) (ResolvedResource, error) {
func (r *FakeResolver) Resolve(_ context.Context, params map[string]string) (framework.ResolvedResource, error) {
paramValue := params[FakeParamName]

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

var _ TimedResolution = &FakeResolver{}
var _ framework.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
@@ -1,20 +1,20 @@
/*
Copyright 2022 The Tekton Authors
Copyright 2022 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package framework
package testing

import (
"encoding/base64"
Expand Down

0 comments on commit 653919d

Please sign in to comment.