Skip to content

Commit

Permalink
update: rename to short_failure_message
Browse files Browse the repository at this point in the history
  • Loading branch information
teodor-yanev committed Sep 12, 2024
1 parent 26b71c7 commit d9a52a8
Show file tree
Hide file tree
Showing 14 changed files with 1,561 additions and 1,562 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- Adds a `evaluation_failure_message` column to the `rule_type` table. The failure message
-- Adds a `short_failure_message` column to the `rule_type` table. The failure message
-- is displayed to the user when a rule evaluation fails.
ALTER TABLE rule_type ADD COLUMN evaluation_failure_message TEXT NOT NULL DEFAULT '';
ALTER TABLE rule_type ADD COLUMN short_failure_message TEXT NOT NULL DEFAULT '';
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE rule_type DROP COLUMN evaluation_failure_message;
ALTER TABLE rule_type DROP COLUMN short_failure_message;
6 changes: 3 additions & 3 deletions database/query/rule_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ INSERT INTO rule_type (
subscription_id,
display_name,
release_phase,
evaluation_failure_message
short_failure_message
) VALUES (
$1,
$2,
Expand All @@ -20,7 +20,7 @@ INSERT INTO rule_type (
sqlc.narg(subscription_id),
sqlc.arg(display_name),
sqlc.arg(release_phase),
sqlc.arg(evaluation_failure_message)
sqlc.arg(short_failure_message)
) RETURNING *;

-- name: ListRuleTypesByProject :many
Expand All @@ -37,7 +37,7 @@ DELETE FROM rule_type WHERE id = $1;

-- name: UpdateRuleType :one
UPDATE rule_type
SET description = $2, definition = sqlc.arg(definition)::jsonb, severity_value = sqlc.arg(severity_value), display_name = sqlc.arg(display_name), release_phase = sqlc.arg(release_phase), evaluation_failure_message = sqlc.arg(evaluation_failure_message)
SET description = $2, definition = sqlc.arg(definition)::jsonb, severity_value = sqlc.arg(severity_value), display_name = sqlc.arg(display_name), release_phase = sqlc.arg(release_phase), short_failure_message = sqlc.arg(short_failure_message)
WHERE id = $1
RETURNING *;

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/ref/proto.md

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

30 changes: 15 additions & 15 deletions internal/db/models.go

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

66 changes: 33 additions & 33 deletions internal/db/rule_types.sql.go

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

38 changes: 19 additions & 19 deletions internal/ruletypes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,18 @@ func (_ *ruleTypeService) CreateRuleType(
return nil, err
}

ruleType = ruleType.WithDefaultDisplayName().WithDefaultEvaluationFailureMessage()
ruleType = ruleType.WithDefaultDisplayName().WithDefaultShortFailureMessage()
newDBRecord, err := qtx.CreateRuleType(ctx, db.CreateRuleTypeParams{
Name: ruleTypeName,
DisplayName: ruleType.GetDisplayName(),
EvaluationFailureMessage: ruleType.GetEvaluationFailureMessage(),
ProjectID: projectID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
Guidance: ruleType.GetGuidance(),
SeverityValue: *severity,
SubscriptionID: uuid.NullUUID{UUID: subscriptionID, Valid: subscriptionID != uuid.Nil},
ReleasePhase: *releasePhase,
Name: ruleTypeName,
DisplayName: ruleType.GetDisplayName(),
ShortFailureMessage: ruleType.GetShortFailureMessage(),
ProjectID: projectID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
Guidance: ruleType.GetGuidance(),
SeverityValue: *severity,
SubscriptionID: uuid.NullUUID{UUID: subscriptionID, Valid: subscriptionID != uuid.Nil},
ReleasePhase: *releasePhase,
})
if err != nil {
return nil, fmt.Errorf("failed to create rule type: %w", err)
Expand Down Expand Up @@ -226,15 +226,15 @@ func (_ *ruleTypeService) UpdateRuleType(
return nil, err
}

ruleType = ruleType.WithDefaultDisplayName().WithDefaultEvaluationFailureMessage()
ruleType = ruleType.WithDefaultDisplayName().WithDefaultShortFailureMessage()
updatedRuleType, err := qtx.UpdateRuleType(ctx, db.UpdateRuleTypeParams{
ID: oldRuleType.ID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
SeverityValue: *severity,
DisplayName: ruleType.GetDisplayName(),
EvaluationFailureMessage: ruleType.GetEvaluationFailureMessage(),
ReleasePhase: *releasePhase,
ID: oldRuleType.ID,
Description: ruleType.GetDescription(),
Definition: serializedRule,
SeverityValue: *severity,
DisplayName: ruleType.GetDisplayName(),
ShortFailureMessage: ruleType.GetShortFailureMessage(),
ReleasePhase: *releasePhase,
})
if err != nil {
return nil, fmt.Errorf("failed to update rule type: %w", err)
Expand Down
32 changes: 16 additions & 16 deletions internal/ruletypes/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ func TestRuleTypeService(t *testing.T) {
},
{
Name: "CreateRuleType with EvaluationFailureMessage",
RuleType: newRuleType(withBasicStructure, withEvaluationFailureMessage(evaluationFailureMessage)),
RuleType: newRuleType(withBasicStructure, withEvaluationFailureMessage(shortFailureMessage)),
DBSetup: dbf.NewDBMock(withHierarchyGet, withNotFoundGet, withSuccessfulCreateWithEvaluationFailureMessage),
TestMethod: create,
},
{
Name: "UpdateRuleType with EvaluationFailureMessage",
RuleType: newRuleType(withBasicStructure, withEvaluationFailureMessage(evaluationFailureMessage)),
RuleType: newRuleType(withBasicStructure, withEvaluationFailureMessage(shortFailureMessage)),
DBSetup: dbf.NewDBMock(withSuccessfulGet, withSuccessfulUpdateWithEvaluationFailureMessage),
TestMethod: update,
},
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestRuleTypeService(t *testing.T) {
// By default this should be the name
require.Equal(t, scenario.RuleType.Name, res.DisplayName)
require.Equal(t, scenario.RuleType.Severity.Value, res.Severity.Value)
require.Equal(t, scenario.RuleType.EvaluationFailureMessage, res.EvaluationFailureMessage)
require.Equal(t, scenario.RuleType.ShortFailureMessage, res.ShortFailureMessage)
}
} else {
require.Nil(t, res)
Expand All @@ -300,10 +300,10 @@ const (
create method = iota
update
upsert
ruleName = "rule_type"
namespacedRuleName = "namespace/rule_type"
description = "this is my awesome rule"
evaluationFailureMessage = "Custom failure message"
ruleName = "rule_type"
namespacedRuleName = "namespace/rule_type"
description = "this is my awesome rule"
shortFailureMessage = "Custom failure message"
)

var (
Expand All @@ -315,7 +315,7 @@ var (
namespacedOldRuleType = newDBRuleType("low", subscriptionID, "")
expectation = newDBRuleType("high", uuid.Nil, "")
namespacedExpectation = newDBRuleType("high", subscriptionID, "")
expectationEvaluationFailureMessage = newDBRuleType("high", uuid.Nil, evaluationFailureMessage)
expectationEvaluationFailureMessage = newDBRuleType("high", uuid.Nil, shortFailureMessage)
incompatibleSchema = &structpb.Struct{
Fields: map[string]*structpb.Value{
"required": {
Expand Down Expand Up @@ -350,7 +350,7 @@ func withBasicStructure(ruleType *pb.RuleType) {

func withEvaluationFailureMessage(message string) func(ruleType *pb.RuleType) {
return func(ruleType *pb.RuleType) {
ruleType.EvaluationFailureMessage = message
ruleType.ShortFailureMessage = message
}
}

Expand Down Expand Up @@ -450,12 +450,12 @@ func newDBRuleType(severity db.Severity, subscriptionID uuid.UUID, failureMessag
failureMessage = "Rule evaluation failed"
}
return db.RuleType{
ID: ruleTypeID,
Name: name,
Definition: []byte(`{}`),
SeverityValue: severity,
Description: description,
SubscriptionID: uuid.NullUUID{Valid: subscriptionID != uuid.Nil, UUID: subscriptionID},
EvaluationFailureMessage: failureMessage,
ID: ruleTypeID,
Name: name,
Definition: []byte(`{}`),
SeverityValue: severity,
Description: description,
SubscriptionID: uuid.NullUUID{Valid: subscriptionID != uuid.Nil, UUID: subscriptionID},
ShortFailureMessage: failureMessage,
}
}
Loading

0 comments on commit d9a52a8

Please sign in to comment.