-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
consequences.go
58 lines (46 loc) · 1.3 KB
/
consequences.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
package repos
import (
"context"
"fmt"
repositorypkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
)
// this implements the "then" part of given/when/then
type Consequences struct {
context *Context
actions *Actions
}
func (c *Consequences) Expect() *Consequences {
return c
}
func (c *Consequences) And(block func(repository *v1alpha1.Repository, err error)) *Consequences {
c.context.t.Helper()
block(c.repo())
return c
}
func (c *Consequences) AndCLIOutput(block func(output string, err error)) *Consequences {
c.context.t.Helper()
block(c.actions.lastOutput, c.actions.lastError)
return c
}
func (c *Consequences) repo() (*v1alpha1.Repository, error) {
app, err := c.get()
return app, err
}
func (c *Consequences) get() (*v1alpha1.Repository, error) {
_, repoClient, _ := fixture.ArgoCDClientset.NewRepoClient()
repo, _ := repoClient.ListRepositories(context.Background(), &repositorypkg.RepoQuery{})
for i := range repo.Items {
if repo.Items[i].Repo == c.context.path {
return repo.Items[i], nil
}
}
return nil, fmt.Errorf("repo not found")
}
func (c *Consequences) Given() *Context {
return c.context
}
func (c *Consequences) When() *Actions {
return c.actions
}