approval status types, tests updates
parent
3ba879996f
commit
4561e28e33
|
@ -47,10 +47,8 @@ type MainCollector struct {
|
|||
}
|
||||
|
||||
// New - create new sender
|
||||
func New(approvalsManager approvals.Manager) *MainCollector {
|
||||
return &MainCollector{
|
||||
approvalsManager: approvalsManager,
|
||||
}
|
||||
func New() *MainCollector {
|
||||
return &MainCollector{}
|
||||
}
|
||||
|
||||
// Configure - configure is used to register multiple notification senders
|
||||
|
|
|
@ -67,7 +67,7 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error
|
|||
identifier := getIdentifier(plan.Deployment.Namespace, plan.Deployment.Name, plan.NewVersion)
|
||||
|
||||
// checking for existing approval
|
||||
existing, err := p.approvalManager.Get(types.ProviderTypeKubernetes, identifier)
|
||||
existing, err := p.approvalManager.Get(identifier)
|
||||
if err != nil {
|
||||
if err == cache.ErrNotFound {
|
||||
|
||||
|
@ -98,5 +98,5 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error
|
|||
return false, err
|
||||
}
|
||||
|
||||
return existing.Approved(), nil
|
||||
return existing.Status() == types.ApprovalStatusApproved, nil
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func TestCheckRequestedApproval(t *testing.T) {
|
|||
}
|
||||
|
||||
// checking approvals
|
||||
approval, err := provider.approvalManager.Get(types.ProviderTypeKubernetes, "xxxx/dep-1:1.1.2")
|
||||
approval, err := provider.approvalManager.Get("xxxx/dep-1:1.1.2")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to find approval, err: %s", err)
|
||||
}
|
||||
|
|
|
@ -304,9 +304,39 @@ type Approval struct {
|
|||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
// Approved - checks if approval is approved
|
||||
func (a *Approval) Approved() bool {
|
||||
return !a.Rejected && a.VotesReceived >= a.VotesRequired
|
||||
type ApprovalStatus int
|
||||
|
||||
const (
|
||||
ApprovalStatusUnknown ApprovalStatus = iota
|
||||
ApprovalStatusPending
|
||||
ApprovalStatusApproved
|
||||
ApprovalStatusRejected
|
||||
)
|
||||
|
||||
func (s ApprovalStatus) String() string {
|
||||
switch s {
|
||||
case ApprovalStatusPending:
|
||||
return "pending"
|
||||
case ApprovalStatusApproved:
|
||||
return "approved"
|
||||
case ApprovalStatusRejected:
|
||||
return "rejected"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// Status - returns current approval status
|
||||
func (a *Approval) Status() ApprovalStatus {
|
||||
if a.Rejected {
|
||||
return ApprovalStatusRejected
|
||||
}
|
||||
|
||||
if a.VotesReceived >= a.VotesRequired {
|
||||
return ApprovalStatusApproved
|
||||
}
|
||||
|
||||
return ApprovalStatusPending
|
||||
}
|
||||
|
||||
// Delta of what's changed
|
||||
|
|
Loading…
Reference in New Issue