Skip to content

Commit

Permalink
update proto
Browse files Browse the repository at this point in the history
  • Loading branch information
dalton-hill-0 committed Mar 25, 2024
1 parent 1e7bc46 commit d83c0a3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 95 deletions.
125 changes: 63 additions & 62 deletions proto/v1beta1/run_function.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/v1beta1/run_function.proto
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ message Result {

// Determines who should receive any Events or Status Conditions that are
// generated as part of this result
repeated Target targets = 3;
Target target = 3;

// Optionally update the supplied status condition on all targets.
// The result's reason and message will be used in the condition.
Expand Down Expand Up @@ -254,7 +254,7 @@ enum Severity {
enum Target {
TARGET_UNSPECIFIED = 0;
TARGET_COMPOSITE = 1;
TARGET_CLAIM = 2;
TARGET_COMPOSITE_AND_CLAIM = 2;
}

// Status of Function result condition.
Expand Down
20 changes: 5 additions & 15 deletions response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Fatal(rsp *v1beta1.RunFunctionResponse, err error) *ResultOption {
result := &v1beta1.Result{
Severity: v1beta1.Severity_SEVERITY_FATAL,
Message: err.Error(),
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
}
rsp.Results = append(rsp.GetResults(), result)

Expand All @@ -129,7 +129,7 @@ func Warning(rsp *v1beta1.RunFunctionResponse, err error) *ResultOption {
result := &v1beta1.Result{
Severity: v1beta1.Severity_SEVERITY_WARNING,
Message: err.Error(),
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
}
rsp.Results = append(rsp.GetResults(), result)

Expand All @@ -147,7 +147,7 @@ func Normal(rsp *v1beta1.RunFunctionResponse, message string) *ResultOption {
result := &v1beta1.Result{
Severity: v1beta1.Severity_SEVERITY_NORMAL,
Message: message,
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
}
rsp.Results = append(rsp.GetResults(), result)

Expand All @@ -162,27 +162,17 @@ func Normalf(rsp *v1beta1.RunFunctionResponse, format string, a ...any) *ResultO
return Normal(rsp, fmt.Sprintf(format, a...))
}

// TargetClaim configures the Claim to receive any events or conditions
// generated by this result.
func (o *ResultOption) TargetClaim() *ResultOption {
o.result.Targets = []v1beta1.Target{v1beta1.Target_TARGET_CLAIM}
return o
}

// TargetComposite configures the Composite to receive any events or conditions
// generated by this result.
func (o *ResultOption) TargetComposite() *ResultOption {
o.result.Targets = []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE}
o.result.Target = v1beta1.Target_TARGET_COMPOSITE
return o
}

// TargetBoth configures both the Claim and Composite to receive any events or
// conditions generated by this result.
func (o *ResultOption) TargetBoth() *ResultOption {
o.result.Targets = []v1beta1.Target{
v1beta1.Target_TARGET_CLAIM,
v1beta1.Target_TARGET_COMPOSITE,
}
o.result.Target = v1beta1.Target_TARGET_COMPOSITE_AND_CLAIM
return o
}

Expand Down
24 changes: 8 additions & 16 deletions response/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ func TestResult(t *testing.T) {
{
Severity: v1beta1.Severity_SEVERITY_NORMAL,
Message: "this is a test normal result",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
},
{
Severity: v1beta1.Severity_SEVERITY_WARNING,
Message: "this is a test warning result",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
},
{
Severity: v1beta1.Severity_SEVERITY_FATAL,
Message: "this is a test fatal result",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
},
},
},
Expand All @@ -79,9 +79,6 @@ func TestResult(t *testing.T) {
reason: "Correctly sets targets on result and adds it to the response.",
args: args{
fns: []testFn{
func(rsp *v1beta1.RunFunctionResponse) {
response.Normal(rsp, "this is a test normal result targeting the claim").TargetClaim()
},
func(rsp *v1beta1.RunFunctionResponse) {
response.Warning(rsp, errors.New("this is a test warning result targeting the composite")).TargetComposite()
},
Expand All @@ -92,20 +89,15 @@ func TestResult(t *testing.T) {
},
want: want{
results: []*v1beta1.Result{
{
Severity: v1beta1.Severity_SEVERITY_NORMAL,
Message: "this is a test normal result targeting the claim",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_CLAIM},
},
{
Severity: v1beta1.Severity_SEVERITY_WARNING,
Message: "this is a test warning result targeting the composite",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
},
{
Severity: v1beta1.Severity_SEVERITY_FATAL,
Message: "this is a test fatal result targeting both",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_CLAIM, v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE_AND_CLAIM,
},
},
},
Expand All @@ -130,7 +122,7 @@ func TestResult(t *testing.T) {
{
Severity: v1beta1.Severity_SEVERITY_NORMAL,
Message: "some-message",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
Condition: &v1beta1.Condition{
Type: "DatabaseReady",
Status: v1beta1.Status_STATUS_TRUE,
Expand All @@ -140,7 +132,7 @@ func TestResult(t *testing.T) {
{
Severity: v1beta1.Severity_SEVERITY_WARNING,
Message: "some-error",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
Condition: &v1beta1.Condition{
Type: "DatabaseReady",
Status: v1beta1.Status_STATUS_UNKNOWN,
Expand All @@ -150,7 +142,7 @@ func TestResult(t *testing.T) {
{
Severity: v1beta1.Severity_SEVERITY_FATAL,
Message: "some-error",
Targets: []v1beta1.Target{v1beta1.Target_TARGET_COMPOSITE},
Target: v1beta1.Target_TARGET_COMPOSITE,
Condition: &v1beta1.Condition{
Type: "DatabaseReady",
Status: v1beta1.Status_STATUS_FALSE,
Expand Down

0 comments on commit d83c0a3

Please sign in to comment.