-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add unit tests for pkg/resolution/resource
#6433
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2023 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 | ||
|
||
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. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
|
||
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// ResolverName is the type used for a resolver's name and is mostly | ||
// used to ensure the function signatures that accept it are clear on the | ||
// purpose for the given string. | ||
type ResolverName string | ||
|
||
// Requester is the interface implemented by a type that knows how to | ||
// submit requests for remote resources. | ||
type Requester interface { | ||
// Submit accepts the name of a resolver to submit a request to | ||
// along with the request itself. | ||
Submit(context.Context, ResolverName, Request) (ResolvedResource, error) | ||
} | ||
|
||
// Request is implemented by any type that represents a single request | ||
// for a remote resource. Implementing this interface gives the underlying | ||
// type an opportunity to control properties such as whether the name of | ||
// a request has particular properties, whether the request should be made | ||
// to a specific namespace, and precisely which parameters should be included. | ||
type Request interface { | ||
Name() string | ||
Namespace() string | ||
Params() pipelinev1beta1.Params | ||
} | ||
|
||
// OwnedRequest is implemented by any type implementing Request that also needs | ||
// to express a Kubernetes OwnerRef relationship as part of the request being | ||
// made. | ||
type OwnedRequest interface { | ||
OwnerRef() metav1.OwnerReference | ||
} | ||
|
||
// ResolvedResource is implemented by any type that offers a read-only | ||
// view of the data and metadata of a resolved remote resource. | ||
type ResolvedResource interface { | ||
Data() ([]byte, error) | ||
Annotations() map[string]string | ||
RefSource() *pipelinev1beta1.RefSource | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move from:
pipeline/pkg/resolution/resource/resource.go
Lines 26 to 63 in 40763d8
avoid cycle import. 😁
The test package references these interfaces.
pipeline/test/resolution.go
Line 12 in 40763d8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although moving the interface to write unit tests is not reasonable, since the methods in the test package are referenced in multiple places, I can only choose the way to make the minimum changes.
And I also need to use existing methods in the test package, I don't want to duplicate them here.