From 84b42c223a47666c79fd3d1996e9bdabd53710fa Mon Sep 17 00:00:00 2001 From: mdrakos Date: Tue, 19 Nov 2024 13:28:04 -0800 Subject: [PATCH] Add date recognition to messages --- cmd/state-svc/internal/messages/messages.go | 44 +- .../internal/messages/messages_test.go | 132 ++- .../internal/server/generated/generated.go | 876 ++++++++++++++---- cmd/state-svc/schema/schema.graphqls | 2 + internal/graph/generated.go | 2 + test/integration/msg_int_test.go | 108 ++- 6 files changed, 963 insertions(+), 201 deletions(-) diff --git a/cmd/state-svc/internal/messages/messages.go b/cmd/state-svc/internal/messages/messages.go index 1495a8a1b2..1717053654 100644 --- a/cmd/state-svc/internal/messages/messages.go +++ b/cmd/state-svc/internal/messages/messages.go @@ -44,7 +44,7 @@ func New(cfg *config.Instance, auth *auth.Auth) (*Messages, error) { return nil, errs.Wrap(err, "Could not parse state version") } - poll := poller.New(1*time.Hour, func() (interface{}, error) { + poll := poller.New(10*time.Minute, func() (interface{}, error) { defer func() { panics.LogAndPanic(recover(), debug.Stack()) }() @@ -112,11 +112,39 @@ func (m *Messages) Check(command string, flags []string) ([]*graph.MessageInfo, return msgs, nil } +func messageInDateRange(message *graph.MessageInfo, baseTime time.Time) (bool, error) { + logging.Debug("Checking message %s in date range with base time %s", message.ID, baseTime.Format(time.RFC3339)) + if message.StartDate != "" { + startDate, err := time.Parse(time.RFC3339, message.StartDate) + if err != nil { + return false, errs.Wrap(err, "Could not parse start date for message %s", message.ID) + } + if baseTime.Before(startDate) { + logging.Debug("Skipping message %s as it is before start date %s", message.ID, startDate.Format(time.RFC3339)) + return false, nil + } + } + + if message.EndDate != "" { + endDate, err := time.Parse(time.RFC3339, message.EndDate) + if err != nil { + return false, errs.Wrap(err, "Could not parse end date for message %s", message.ID) + } + if baseTime.After(endDate) { + logging.Debug("Skipping message %s as it is after end date %s", message.ID, endDate.Format(time.RFC3339)) + return false, nil + } + } + + return true, nil +} + func check(params *ConditionParams, messages []*graph.MessageInfo, lastReportMap map[string]interface{}, baseTime time.Time) ([]*graph.MessageInfo, error) { funcMap := conditionFuncMap() filteredMessages := []*graph.MessageInfo{} for _, message := range messages { logging.Debug("Checking message %s", message.ID) + // Ensure we don't show the same message too often if lastReport, ok := lastReportMap[message.ID]; ok { lr, ok := lastReport.(string) @@ -140,11 +168,23 @@ func check(params *ConditionParams, messages []*graph.MessageInfo, lastReportMap } } + // Check if message is within date range + inRange, err := messageInDateRange(message, baseTime) + if err != nil { + logging.Warning("Could not check if message %s is in date range: %v", message.ID, err) + continue + } + if !inRange { + logging.Debug("Skipping message %s as it is outside of its date range", message.ID) + continue + } + // Validate the conditional if message.Condition != "" { result, err := strutils.ParseTemplate(fmt.Sprintf(`{{%s}}`, message.Condition), params, funcMap) if err != nil { - return nil, errs.Wrap(err, "Could not parse condition template for message %s", message.ID) + logging.Warning("Could not parse condition template for message %s: %v", message.ID, err) + continue } if result == "true" { logging.Debug("Including message %s as condition %s evaluated to %s", message.ID, message.Condition, result) diff --git a/cmd/state-svc/internal/messages/messages_test.go b/cmd/state-svc/internal/messages/messages_test.go index ffaf24f92a..186bc6719e 100644 --- a/cmd/state-svc/internal/messages/messages_test.go +++ b/cmd/state-svc/internal/messages/messages_test.go @@ -11,6 +11,7 @@ import ( ) func Test_check(t *testing.T) { + baseTime := time.Now() type args struct { params *ConditionParams messages []*graph.MessageInfo @@ -31,7 +32,7 @@ func Test_check(t *testing.T) { {ID: "A"}, {ID: "B"}, {ID: "C"}, }, lastReportMap: map[string]interface{}{}, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"A", "B", "C"}, false, @@ -48,7 +49,7 @@ func Test_check(t *testing.T) { {ID: "C", Condition: `eq .Command "foobar"`}, }, lastReportMap: map[string]interface{}{}, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"B"}, false, @@ -64,7 +65,7 @@ func Test_check(t *testing.T) { {ID: "B", Condition: `contains .UserEmail "fred"`}, }, lastReportMap: map[string]interface{}{}, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"A"}, false, @@ -80,7 +81,7 @@ func Test_check(t *testing.T) { {ID: "B", Condition: `hasPrefix .UserEmail "org"`}, }, lastReportMap: map[string]interface{}{}, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"A"}, false, @@ -96,7 +97,7 @@ func Test_check(t *testing.T) { {ID: "B", Condition: `hasSuffix .UserEmail "org"`}, }, lastReportMap: map[string]interface{}{}, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"B"}, false, @@ -112,7 +113,7 @@ func Test_check(t *testing.T) { {ID: "B", Condition: `regexMatch .UserEmail "^doe.org$"`}, }, lastReportMap: map[string]interface{}{}, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"A"}, false, @@ -128,7 +129,7 @@ func Test_check(t *testing.T) { {ID: "B", Condition: `regexMatch .UserEmail ".*("`}, }, lastReportMap: map[string]interface{}{}, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"A"}, false, @@ -150,7 +151,7 @@ func Test_check(t *testing.T) { {ID: "H", Condition: `eq .StateVersion.Build "foo"`}, }, lastReportMap: map[string]interface{}{}, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"A", "B", "C", "D"}, false, @@ -165,10 +166,10 @@ func Test_check(t *testing.T) { {ID: "C", Repeat: graph.MessageRepeatTypeDisabled}, }, lastReportMap: map[string]interface{}{ - "A": time.Now(), - "C": time.Now(), + "A": baseTime.Format(time.RFC3339), + "C": baseTime.Format(time.RFC3339), }, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"B"}, false, @@ -183,10 +184,10 @@ func Test_check(t *testing.T) { {ID: "C", Repeat: graph.MessageRepeatTypeConstantly}, }, lastReportMap: map[string]interface{}{ - "A": time.Now(), - "C": time.Now().Add(-time.Hour * 24 * 30), + "A": baseTime.Format(time.RFC3339), + "C": baseTime.Add(-time.Hour * 24 * 30).Format(time.RFC3339), }, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"A", "B", "C"}, false, @@ -201,11 +202,11 @@ func Test_check(t *testing.T) { {ID: "C", Repeat: graph.MessageRepeatTypeHourly}, }, lastReportMap: map[string]interface{}{ - "A": time.Now(), - "B": time.Now().Add(-time.Hour), - "C": time.Now(), + "A": baseTime.Format(time.RFC3339), + "B": baseTime.Add(-time.Hour).Format(time.RFC3339), + "C": baseTime.Format(time.RFC3339), }, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"B"}, false, @@ -220,11 +221,11 @@ func Test_check(t *testing.T) { {ID: "C", Repeat: graph.MessageRepeatTypeHourly}, }, lastReportMap: map[string]interface{}{ - "A": time.Now(), - "B": time.Now().Add(-time.Hour * 24), - "C": time.Now(), + "A": baseTime.Format(time.RFC3339), + "B": baseTime.Add(-time.Hour * 24).Format(time.RFC3339), + "C": baseTime.Format(time.RFC3339), }, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"B"}, false, @@ -239,11 +240,11 @@ func Test_check(t *testing.T) { {ID: "C", Repeat: graph.MessageRepeatTypeHourly}, }, lastReportMap: map[string]interface{}{ - "A": time.Now(), - "B": time.Now().Add(-time.Hour * 24 * 7), - "C": time.Now(), + "A": baseTime.Format(time.RFC3339), + "B": baseTime.Add(-time.Hour * 24 * 7).Format(time.RFC3339), + "C": baseTime.Format(time.RFC3339), }, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"B"}, false, @@ -258,15 +259,86 @@ func Test_check(t *testing.T) { {ID: "C", Repeat: graph.MessageRepeatTypeHourly}, }, lastReportMap: map[string]interface{}{ - "A": time.Now(), - "B": time.Now().Add(-time.Hour * 24 * 7 * 30), - "C": time.Now(), + "A": baseTime.Format(time.RFC3339), + "B": baseTime.Add(-time.Hour * 24 * 7 * 30).Format(time.RFC3339), + "C": baseTime.Format(time.RFC3339), }, - baseTime: time.Now(), + baseTime: baseTime, }, []string{"B"}, false, }, + { + "Date Range - Within Range", + args{ + params: &ConditionParams{}, + messages: []*graph.MessageInfo{ + {ID: "A", StartDate: baseTime.Add(-24 * time.Hour).Format(time.RFC3339), EndDate: baseTime.Add(24 * time.Hour).Format(time.RFC3339)}, + {ID: "B", StartDate: baseTime.Add(-1 * time.Hour).Format(time.RFC3339), EndDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339)}, + {ID: "C", StartDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339), EndDate: baseTime.Add(24 * time.Hour).Format(time.RFC3339)}, + }, + lastReportMap: map[string]interface{}{}, + baseTime: baseTime, + }, + []string{"A", "B"}, + false, + }, + { + "Date Range - No Dates Specified", + args{ + params: &ConditionParams{}, + messages: []*graph.MessageInfo{ + {ID: "A"}, + {ID: "B", StartDate: baseTime.Add(-1 * time.Hour).Format(time.RFC3339)}, + {ID: "C", EndDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339)}, + }, + lastReportMap: map[string]interface{}{}, + baseTime: baseTime, + }, + []string{"A", "B", "C"}, + false, + }, + { + "Date Range - Invalid Date Format", + args{ + params: &ConditionParams{}, + messages: []*graph.MessageInfo{ + {ID: "A", StartDate: "invalid-date"}, + }, + lastReportMap: map[string]interface{}{}, + baseTime: baseTime, + }, + []string{}, + true, + }, + { + "Date Range - Only Start Date", + args{ + params: &ConditionParams{}, + messages: []*graph.MessageInfo{ + {ID: "A", StartDate: baseTime.Add(-1 * time.Hour).Format(time.RFC3339)}, + {ID: "B", StartDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339)}, + }, + lastReportMap: map[string]interface{}{}, + baseTime: baseTime, + }, + []string{"A"}, + false, + }, + { + "Date Range - Only End Date", + args{ + params: &ConditionParams{}, + messages: []*graph.MessageInfo{ + {ID: "A", EndDate: baseTime.Add(1 * time.Hour).Format(time.RFC3339)}, + {ID: "B", EndDate: baseTime.Add(-1 * time.Hour).Format(time.RFC3339)}, + }, + lastReportMap: map[string]interface{}{}, + baseTime: baseTime, + }, + []string{"A"}, + false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/cmd/state-svc/internal/server/generated/generated.go b/cmd/state-svc/internal/server/generated/generated.go index 16617b4d7b..cfb794c9ee 100644 --- a/cmd/state-svc/internal/server/generated/generated.go +++ b/cmd/state-svc/internal/server/generated/generated.go @@ -81,11 +81,13 @@ type ComplexityRoot struct { MessageInfo struct { Condition func(childComplexity int) int + EndDate func(childComplexity int) int ID func(childComplexity int) int Interrupt func(childComplexity int) int Message func(childComplexity int) int Placement func(childComplexity int) int Repeat func(childComplexity int) int + StartDate func(childComplexity int) int } Mutation struct { @@ -288,6 +290,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MessageInfo.Condition(childComplexity), true + case "MessageInfo.endDate": + if e.complexity.MessageInfo.EndDate == nil { + break + } + + return e.complexity.MessageInfo.EndDate(childComplexity), true + case "MessageInfo.id": if e.complexity.MessageInfo.ID == nil { break @@ -323,6 +332,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MessageInfo.Repeat(childComplexity), true + case "MessageInfo.startDate": + if e.complexity.MessageInfo.StartDate == nil { + break + } + + return e.complexity.MessageInfo.StartDate(childComplexity), true + case "Mutation.setCache": if e.complexity.Mutation.SetCache == nil { break @@ -739,6 +755,8 @@ type MessageInfo { id: String! message: String! condition: String! + startDate: String! + endDate: String! repeat: MessageRepeatType! interrupt: MessageInterruptType! placement: MessagePlacementType! @@ -812,290 +830,710 @@ var parsedSchema = gqlparser.MustLoadSchema(sources...) func (ec *executionContext) field_Mutation_setCache_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["key"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Mutation_setCache_argsKey(ctx, rawArgs) + if err != nil { + return nil, err } args["key"] = arg0 - var arg1 string - if tmp, ok := rawArgs["value"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) - arg1, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg1, err := ec.field_Mutation_setCache_argsValue(ctx, rawArgs) + if err != nil { + return nil, err } args["value"] = arg1 - var arg2 int - if tmp, ok := rawArgs["expiry"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("expiry")) - arg2, err = ec.unmarshalNInt2int(ctx, tmp) - if err != nil { - return nil, err - } + arg2, err := ec.field_Mutation_setCache_argsExpiry(ctx, rawArgs) + if err != nil { + return nil, err } args["expiry"] = arg2 return args, nil } +func (ec *executionContext) field_Mutation_setCache_argsKey( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["key"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) + if tmp, ok := rawArgs["key"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Mutation_setCache_argsValue( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["value"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("value")) + if tmp, ok := rawArgs["value"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Mutation_setCache_argsExpiry( + ctx context.Context, + rawArgs map[string]interface{}, +) (int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["expiry"] + if !ok { + var zeroVal int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("expiry")) + if tmp, ok := rawArgs["expiry"]; ok { + return ec.unmarshalNInt2int(ctx, tmp) + } + + var zeroVal int + return zeroVal, nil +} func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["name"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query___type_argsName(ctx, rawArgs) + if err != nil { + return nil, err } args["name"] = arg0 return args, nil } +func (ec *executionContext) field_Query___type_argsName( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["name"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + if tmp, ok := rawArgs["name"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field_Query_analyticsEvent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["category"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("category")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query_analyticsEvent_argsCategory(ctx, rawArgs) + if err != nil { + return nil, err } args["category"] = arg0 - var arg1 string - if tmp, ok := rawArgs["action"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("action")) - arg1, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg1, err := ec.field_Query_analyticsEvent_argsAction(ctx, rawArgs) + if err != nil { + return nil, err } args["action"] = arg1 - var arg2 string - if tmp, ok := rawArgs["source"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) - arg2, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg2, err := ec.field_Query_analyticsEvent_argsSource(ctx, rawArgs) + if err != nil { + return nil, err } args["source"] = arg2 - var arg3 *string - if tmp, ok := rawArgs["label"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("label")) - arg3, err = ec.unmarshalOString2ᚖstring(ctx, tmp) - if err != nil { - return nil, err - } + arg3, err := ec.field_Query_analyticsEvent_argsLabel(ctx, rawArgs) + if err != nil { + return nil, err } args["label"] = arg3 - var arg4 string - if tmp, ok := rawArgs["dimensionsJson"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("dimensionsJson")) - arg4, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg4, err := ec.field_Query_analyticsEvent_argsDimensionsJSON(ctx, rawArgs) + if err != nil { + return nil, err } args["dimensionsJson"] = arg4 return args, nil } +func (ec *executionContext) field_Query_analyticsEvent_argsCategory( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["category"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("category")) + if tmp, ok := rawArgs["category"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_analyticsEvent_argsAction( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["action"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("action")) + if tmp, ok := rawArgs["action"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_analyticsEvent_argsSource( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["source"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) + if tmp, ok := rawArgs["source"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_analyticsEvent_argsLabel( + ctx context.Context, + rawArgs map[string]interface{}, +) (*string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["label"] + if !ok { + var zeroVal *string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("label")) + if tmp, ok := rawArgs["label"]; ok { + return ec.unmarshalOString2ᚖstring(ctx, tmp) + } + + var zeroVal *string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_analyticsEvent_argsDimensionsJSON( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["dimensionsJson"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("dimensionsJson")) + if tmp, ok := rawArgs["dimensionsJson"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field_Query_availableUpdate_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["desiredChannel"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("desiredChannel")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query_availableUpdate_argsDesiredChannel(ctx, rawArgs) + if err != nil { + return nil, err } args["desiredChannel"] = arg0 - var arg1 string - if tmp, ok := rawArgs["desiredVersion"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("desiredVersion")) - arg1, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg1, err := ec.field_Query_availableUpdate_argsDesiredVersion(ctx, rawArgs) + if err != nil { + return nil, err } args["desiredVersion"] = arg1 return args, nil } +func (ec *executionContext) field_Query_availableUpdate_argsDesiredChannel( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["desiredChannel"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("desiredChannel")) + if tmp, ok := rawArgs["desiredChannel"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_availableUpdate_argsDesiredVersion( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["desiredVersion"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("desiredVersion")) + if tmp, ok := rawArgs["desiredVersion"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field_Query_checkMessages_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["command"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("command")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query_checkMessages_argsCommand(ctx, rawArgs) + if err != nil { + return nil, err } args["command"] = arg0 - var arg1 []string - if tmp, ok := rawArgs["flags"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("flags")) - arg1, err = ec.unmarshalNString2ᚕstringᚄ(ctx, tmp) - if err != nil { - return nil, err - } + arg1, err := ec.field_Query_checkMessages_argsFlags(ctx, rawArgs) + if err != nil { + return nil, err } args["flags"] = arg1 return args, nil } +func (ec *executionContext) field_Query_checkMessages_argsCommand( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["command"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("command")) + if tmp, ok := rawArgs["command"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_checkMessages_argsFlags( + ctx context.Context, + rawArgs map[string]interface{}, +) ([]string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["flags"] + if !ok { + var zeroVal []string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("flags")) + if tmp, ok := rawArgs["flags"]; ok { + return ec.unmarshalNString2ᚕstringᚄ(ctx, tmp) + } + + var zeroVal []string + return zeroVal, nil +} func (ec *executionContext) field_Query_configChanged_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["key"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query_configChanged_argsKey(ctx, rawArgs) + if err != nil { + return nil, err } args["key"] = arg0 return args, nil } +func (ec *executionContext) field_Query_configChanged_argsKey( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["key"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) + if tmp, ok := rawArgs["key"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field_Query_getCache_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["key"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query_getCache_argsKey(ctx, rawArgs) + if err != nil { + return nil, err } args["key"] = arg0 return args, nil } +func (ec *executionContext) field_Query_getCache_argsKey( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["key"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("key")) + if tmp, ok := rawArgs["key"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field_Query_getProcessesInUse_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["execDir"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("execDir")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query_getProcessesInUse_argsExecDir(ctx, rawArgs) + if err != nil { + return nil, err } args["execDir"] = arg0 return args, nil } +func (ec *executionContext) field_Query_getProcessesInUse_argsExecDir( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["execDir"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("execDir")) + if tmp, ok := rawArgs["execDir"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field_Query_hashGlobs_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 string - if tmp, ok := rawArgs["wd"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("wd")) - arg0, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query_hashGlobs_argsWd(ctx, rawArgs) + if err != nil { + return nil, err } args["wd"] = arg0 - var arg1 []string - if tmp, ok := rawArgs["globs"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("globs")) - arg1, err = ec.unmarshalNString2ᚕstringᚄ(ctx, tmp) - if err != nil { - return nil, err - } + arg1, err := ec.field_Query_hashGlobs_argsGlobs(ctx, rawArgs) + if err != nil { + return nil, err } args["globs"] = arg1 return args, nil } +func (ec *executionContext) field_Query_hashGlobs_argsWd( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["wd"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("wd")) + if tmp, ok := rawArgs["wd"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_hashGlobs_argsGlobs( + ctx context.Context, + rawArgs map[string]interface{}, +) ([]string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["globs"] + if !ok { + var zeroVal []string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("globs")) + if tmp, ok := rawArgs["globs"]; ok { + return ec.unmarshalNString2ᚕstringᚄ(ctx, tmp) + } + + var zeroVal []string + return zeroVal, nil +} func (ec *executionContext) field_Query_reportRuntimeUsage_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 int - if tmp, ok := rawArgs["pid"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("pid")) - arg0, err = ec.unmarshalNInt2int(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field_Query_reportRuntimeUsage_argsPid(ctx, rawArgs) + if err != nil { + return nil, err } args["pid"] = arg0 - var arg1 string - if tmp, ok := rawArgs["exec"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("exec")) - arg1, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg1, err := ec.field_Query_reportRuntimeUsage_argsExec(ctx, rawArgs) + if err != nil { + return nil, err } args["exec"] = arg1 - var arg2 string - if tmp, ok := rawArgs["source"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) - arg2, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg2, err := ec.field_Query_reportRuntimeUsage_argsSource(ctx, rawArgs) + if err != nil { + return nil, err } args["source"] = arg2 - var arg3 string - if tmp, ok := rawArgs["dimensionsJson"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("dimensionsJson")) - arg3, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } + arg3, err := ec.field_Query_reportRuntimeUsage_argsDimensionsJSON(ctx, rawArgs) + if err != nil { + return nil, err } args["dimensionsJson"] = arg3 return args, nil } +func (ec *executionContext) field_Query_reportRuntimeUsage_argsPid( + ctx context.Context, + rawArgs map[string]interface{}, +) (int, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["pid"] + if !ok { + var zeroVal int + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("pid")) + if tmp, ok := rawArgs["pid"]; ok { + return ec.unmarshalNInt2int(ctx, tmp) + } + + var zeroVal int + return zeroVal, nil +} + +func (ec *executionContext) field_Query_reportRuntimeUsage_argsExec( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["exec"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("exec")) + if tmp, ok := rawArgs["exec"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_reportRuntimeUsage_argsSource( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["source"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("source")) + if tmp, ok := rawArgs["source"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} + +func (ec *executionContext) field_Query_reportRuntimeUsage_argsDimensionsJSON( + ctx context.Context, + rawArgs map[string]interface{}, +) (string, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["dimensionsJson"] + if !ok { + var zeroVal string + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("dimensionsJson")) + if tmp, ok := rawArgs["dimensionsJson"]; ok { + return ec.unmarshalNString2string(ctx, tmp) + } + + var zeroVal string + return zeroVal, nil +} func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field___Type_enumValues_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err } args["includeDeprecated"] = arg0 return args, nil } +func (ec *executionContext) field___Type_enumValues_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]interface{}, +) (bool, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["includeDeprecated"] + if !ok { + var zeroVal bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2bool(ctx, tmp) + } + + var zeroVal bool + return zeroVal, nil +} func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) - if err != nil { - return nil, err - } + arg0, err := ec.field___Type_fields_argsIncludeDeprecated(ctx, rawArgs) + if err != nil { + return nil, err } args["includeDeprecated"] = arg0 return args, nil } +func (ec *executionContext) field___Type_fields_argsIncludeDeprecated( + ctx context.Context, + rawArgs map[string]interface{}, +) (bool, error) { + // We won't call the directive if the argument is null. + // Set call_argument_directives_with_null to true to call directives + // even if the argument is null. + _, ok := rawArgs["includeDeprecated"] + if !ok { + var zeroVal bool + return zeroVal, nil + } + + ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + if tmp, ok := rawArgs["includeDeprecated"]; ok { + return ec.unmarshalOBoolean2bool(ctx, tmp) + } + + var zeroVal bool + return zeroVal, nil +} // endregion ***************************** args.gotpl ***************************** @@ -1871,6 +2309,94 @@ func (ec *executionContext) fieldContext_MessageInfo_condition(_ context.Context return fc, nil } +func (ec *executionContext) _MessageInfo_startDate(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_MessageInfo_startDate(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.StartDate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_MessageInfo_startDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "MessageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _MessageInfo_endDate(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_MessageInfo_endDate(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EndDate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_MessageInfo_endDate(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "MessageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _MessageInfo_repeat(ctx context.Context, field graphql.CollectedField, obj *graph.MessageInfo) (ret graphql.Marshaler) { fc, err := ec.fieldContext_MessageInfo_repeat(ctx, field) if err != nil { @@ -2635,6 +3161,10 @@ func (ec *executionContext) fieldContext_Query_checkMessages(ctx context.Context return ec.fieldContext_MessageInfo_message(ctx, field) case "condition": return ec.fieldContext_MessageInfo_condition(ctx, field) + case "startDate": + return ec.fieldContext_MessageInfo_startDate(ctx, field) + case "endDate": + return ec.fieldContext_MessageInfo_endDate(ctx, field) case "repeat": return ec.fieldContext_MessageInfo_repeat(ctx, field) case "interrupt": @@ -5695,6 +6225,16 @@ func (ec *executionContext) _MessageInfo(ctx context.Context, sel ast.SelectionS if out.Values[i] == graphql.Null { out.Invalids++ } + case "startDate": + out.Values[i] = ec._MessageInfo_startDate(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "endDate": + out.Values[i] = ec._MessageInfo_endDate(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "repeat": out.Values[i] = ec._MessageInfo_repeat(ctx, field, obj) if out.Values[i] == graphql.Null { diff --git a/cmd/state-svc/schema/schema.graphqls b/cmd/state-svc/schema/schema.graphqls index 2d0cb8b23d..9f71c26909 100644 --- a/cmd/state-svc/schema/schema.graphqls +++ b/cmd/state-svc/schema/schema.graphqls @@ -55,6 +55,8 @@ type MessageInfo { id: String! message: String! condition: String! + startDate: String! + endDate: String! repeat: MessageRepeatType! interrupt: MessageInterruptType! placement: MessagePlacementType! diff --git a/internal/graph/generated.go b/internal/graph/generated.go index a9c307c88d..61f7178059 100644 --- a/internal/graph/generated.go +++ b/internal/graph/generated.go @@ -44,6 +44,8 @@ type MessageInfo struct { ID string `json:"id"` Message string `json:"message"` Condition string `json:"condition"` + StartDate string `json:"startDate"` + EndDate string `json:"endDate"` Repeat MessageRepeatType `json:"repeat"` Interrupt MessageInterruptType `json:"interrupt"` Placement MessagePlacementType `json:"placement"` diff --git a/test/integration/msg_int_test.go b/test/integration/msg_int_test.go index 0224d3ad3d..08a983cd63 100644 --- a/test/integration/msg_int_test.go +++ b/test/integration/msg_int_test.go @@ -36,6 +36,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { Name string MessageJson string ExpectRepeat bool + ExpectShown bool }{ { "Defaults", @@ -44,6 +45,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Message": "This is a [NOTICE]simple[/RESET] message" }]`, false, + true, }, { "Repeat Hourly", @@ -53,6 +55,7 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Repeat": "Hourly" }]`, false, + true, }, { "Repeat Constantly", @@ -62,6 +65,103 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { "Repeat": "Constantly" }]`, true, + true, + }, + { + "Within Date Range", + fmt.Sprintf(`[{ + "ID": "simple", + "Message": "This is a [NOTICE]simple[/RESET] message", + "StartDate": "%s", + "EndDate": "%s" + }]`, + time.Now().Add(-1*time.Hour).Format(time.RFC3339), + time.Now().Add(1*time.Hour).Format(time.RFC3339)), + false, + true, + }, + { + "Outside Date Range", + fmt.Sprintf(`[{ + "ID": "simple", + "Message": "This is a [NOTICE]simple[/RESET] message", + "StartDate": "%s", + "EndDate": "%s" + }]`, + time.Now().Add(1*time.Hour).Format(time.RFC3339), + time.Now().Add(2*time.Hour).Format(time.RFC3339)), + false, + false, + }, + { + "Only Start Date - Valid", + fmt.Sprintf(`[{ + "ID": "simple", + "Message": "This is a [NOTICE]simple[/RESET] message", + "StartDate": "%s" + }]`, + time.Now().Add(-1*time.Hour).Format(time.RFC3339)), + false, + true, + }, + { + "Only End Date - Valid", + fmt.Sprintf(`[{ + "ID": "simple", + "Message": "This is a [NOTICE]simple[/RESET] message", + "EndDate": "%s" + }]`, + time.Now().Add(1*time.Hour).Format(time.RFC3339)), + false, + true, + }, + { + "Outside Date Range - Future", + fmt.Sprintf(`[{ + "ID": "simple", + "Message": "This is a [NOTICE]simple[/RESET] message", + "StartDate": "%s", + "EndDate": "%s" + }]`, + time.Now().Add(1*time.Hour).Format(time.RFC3339), + time.Now().Add(2*time.Hour).Format(time.RFC3339)), + false, + false, + }, + { + "Outside Date Range - Past", + fmt.Sprintf(`[{ + "ID": "simple", + "Message": "This is a [NOTICE]simple[/RESET] message", + "StartDate": "%s", + "EndDate": "%s" + }]`, + time.Now().Add(-2*time.Hour).Format(time.RFC3339), + time.Now().Add(-1*time.Hour).Format(time.RFC3339)), + false, + false, + }, + { + "Only Start Date - Invalid", + fmt.Sprintf(`[{ + "ID": "simple", + "Message": "This is a [NOTICE]simple[/RESET] message", + "StartDate": "%s" + }]`, + time.Now().Add(1*time.Hour).Format(time.RFC3339)), + false, + false, + }, + { + "Only End Date - Invalid", + fmt.Sprintf(`[{ + "ID": "simple", + "Message": "This is a [NOTICE]simple[/RESET] message", + "EndDate": "%s" + }]`, + time.Now().Add(-1*time.Hour).Format(time.RFC3339)), + false, + false, }, } for _, tt := range tests { @@ -73,7 +173,13 @@ func (suite *MsgIntegrationTestSuite) TestMessage_Basic() { suite.Require().NoError(err) cp := ts.SpawnWithOpts(e2e.OptArgs("--version"), e2e.OptAppendEnv(constants.MessagesOverrideEnvVarName+"="+msgFile)) - cp.Expect(`This is a simple message`) + + if !tt.ExpectShown { + suite.Require().NotContains(cp.Output(), "This is a simple message", "Message should not appear when outside date range") + } else { + cp.Expect(`This is a simple message`) + } + cp.Expect("ActiveState CLI by ActiveState Software Inc.") cp.ExpectExitCode(0)