@@ -18,41 +18,65 @@ package komega
1818
1919import (
2020 "context"
21- "time"
2221
23- "github.com/onsi/gomega"
24- "k8s.io/apimachinery/pkg/runtime"
2522 "sigs.k8s.io/controller-runtime/pkg/client"
2623)
2724
2825// Komega is the root interface that the Matcher implements.
2926type Komega interface {
30- KomegaAsync
31- KomegaSync
32- WithContext (context.Context ) Komega
33- }
27+ // Get returns a function that fetches a resource and returns the occurring error.
28+ // It can be used with gomega.Eventually() like this
29+ // deployment := appsv1.Deployment{ ... }
30+ // gomega.Eventually(k.Get(&deployment)).To(gomega.Succeed())
31+ // By calling the returned function directly it can also be used with gomega.Expect(k.Get(...)()).To(...)
32+ Get (client.Object ) func () error
3433
35- // KomegaSync is the interface for any sync assertions that
36- // the matcher implements.
37- type KomegaSync interface {
38- Create (client.Object , ... client.CreateOption ) gomega.GomegaAssertion
39- Delete (client.Object , ... client.DeleteOption ) gomega.GomegaAssertion
40- WithExtras (... interface {}) KomegaSync
41- }
34+ // List returns a function that lists resources and returns the occurring error.
35+ // It can be used with gomega.Eventually() like this
36+ // deployments := v1.DeploymentList{ ... }
37+ // gomega.Eventually(k.List(&deployments)).To(gomega.Succeed())
38+ // By calling the returned function directly it can also be used as gomega.Expect(k.List(...)()).To(...)
39+ List (client.ObjectList , ... client.ListOption ) func () error
40+
41+ // Update returns a function that fetches a resource, applies the provided update function and then updates the resource.
42+ // It can be used with gomega.Eventually() like this:
43+ // deployment := appsv1.Deployment{ ... }
44+ // gomega.Eventually(k.Update(&deployment, func (o client.Object) {
45+ // deployment.Spec.Replicas = 3
46+ // return &deployment
47+ // })).To(gomega.Scucceed())
48+ // By calling the returned function directly it can also be used as gomega.Expect(k.Update(...)()).To(...)
49+ Update (client.Object , UpdateFunc , ... client.UpdateOption ) func () error
4250
43- // KomegaAsync is the interface for any async assertions that
44- // the matcher implements.
45- type KomegaAsync interface {
46- Consistently (runtime.Object , ... client.ListOption ) gomega.AsyncAssertion
47- Eventually (runtime.Object , ... client.ListOption ) gomega.AsyncAssertion
48- Get (client.Object ) gomega.AsyncAssertion
49- List (client.ObjectList , ... client.ListOption ) gomega.AsyncAssertion
50- Update (client.Object , UpdateFunc , ... client.UpdateOption ) gomega.AsyncAssertion
51- UpdateStatus (client.Object , UpdateFunc , ... client.UpdateOption ) gomega.AsyncAssertion
52- WithTimeout (time.Duration ) KomegaAsync
53- WithPollInterval (time.Duration ) KomegaAsync
51+ // UpdateStatus returns a function that fetches a resource, applies the provided update function and then updates the resource's status.
52+ // It can be used with gomega.Eventually() like this:
53+ // deployment := appsv1.Deployment{ ... }
54+ // gomega.Eventually(k.Update(&deployment, func (o client.Object) {
55+ // deployment.Status.AvailableReplicas = 1
56+ // return &deployment
57+ // })).To(gomega.Scucceed())
58+ // By calling the returned function directly it can also be used as gomega.Expect(k.UpdateStatus(...)()).To(...)
59+ UpdateStatus (client.Object , UpdateFunc , ... client.UpdateOption ) func () error
60+
61+ // Object returns a function that fetches a resource and returns the object.
62+ // It can be used with gomega.Eventually() like this:
63+ // deployment := appsv1.Deployment{ ... }
64+ // gomega.Eventually(k.Object(&deployment)).To(HaveField("Spec.Replicas", gomega.Equal(pointer.Int32(3))))
65+ // By calling the returned function directly it can also be used as gomega.Expect(k.Object(...)()).To(...)
66+ Object (client.Object ) func () (client.Object , error )
67+
68+ // ObjectList returns a function that fetches a resource and returns the object.
69+ // It can be used with gomega.Eventually() like this:
70+ // deployments := appsv1.DeploymentList{ ... }
71+ // gomega.Eventually(k.ObjectList(&deployments)).To(HaveField("Items", HaveLen(1)))
72+ // By calling the returned function directly it can also be used as gomega.Expect(k.ObjectList(...)()).To(...)
73+ ObjectList (client.ObjectList , ... client.ListOption ) func () (client.ObjectList , error )
74+
75+ // WithClient returns a copy that uses the given client.
76+ WithClient (client.Client ) Komega
77+ // WithContext returns a copy that uses the given context.
78+ WithContext (context.Context ) Komega
5479}
5580
56- // UpdateFunc modifies the object fetched from the API server before sending
57- // the update
81+ // UpdateFunc receives an object and expects a modified version of it to be returned.
5882type UpdateFunc func (client.Object ) client.Object
0 commit comments