forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
63 lines (51 loc) · 2.07 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Copyright 2019 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 builder holds Builder functions that can be used to create
struct in tests with less noise.
One of the most important characteristic of a unit test (and any type
of test really) is readability. This means it should be easy to read
but most importantly it should clearly show the intent of the
test. The setup (and cleanup) of the tests should be as small as
possible to avoid the noise. Those builders exists to help with that.
There is two types of functions defined in that package :
* Builders: create and return a struct
* Modifiers: return a function
that will operate on a given struct. They can be applied to other
Modifiers or Builders.
Most of the Builder (and Modifier) that accepts Modifiers defines a
type (`TypeOp`) that can be satisfied by existing function in this
package, from other package *or* inline. An example would be the
following.
// Definition
type TaskOp func(*v1alpha1.Task)
func Task(name string, ops ...TaskOp) *v1alpha1.Task {
// […]
}
func TaskNamespace(namespace string) TaskOp {
return func(t *v1alpha1.Task) {
// […]
}
}
// Usage
t := Task("foo", TaskNamespace("bar"), func(t *v1alpha1.Task){
// Do something with the Task struct
// […]
})
The main reason to define the `Op` type, and using it in the methods
signatures is to group Modifier function together. It makes it easier
to see what is a Modifier (or Builder) and on what it operates.
By convention, this package is import with the "tb" as alias. The
examples make that assumption.
*/
package builder