mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
Added TestEventForDifferentHost for calendar_cron. (#17802)
Added TestEventForDifferentHost for calendar_cron.
This commit is contained in:
parent
a10aac29c6
commit
62049b04bd
1 changed files with 87 additions and 0 deletions
|
|
@ -1,6 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
"github.com/fleetdm/fleet/v4/server/mock"
|
||||
kitlog "github.com/go-kit/log"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -8,6 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGetPreferredCalendarEventDate(t *testing.T) {
|
||||
t.Parallel()
|
||||
date := func(year int, month time.Month, day int) time.Time {
|
||||
return time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
|
||||
}
|
||||
|
|
@ -103,3 +109,84 @@ func TestGetPreferredCalendarEventDate(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestEventForDifferentHost tests case when event exists, but for a different host. Nothing should happen.
|
||||
// The old event will eventually be cleaned up by the cleanup job, and afterward a new event will be created.
|
||||
func TestEventForDifferentHost(t *testing.T) {
|
||||
t.Parallel()
|
||||
ds := new(mock.Store)
|
||||
ctx := context.Background()
|
||||
logger := kitlog.With(kitlog.NewLogfmtLogger(os.Stdout))
|
||||
ds.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) {
|
||||
return &fleet.AppConfig{
|
||||
Integrations: fleet.Integrations{
|
||||
GoogleCalendar: []*fleet.GoogleCalendarIntegration{
|
||||
{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
teamID1 := uint(1)
|
||||
ds.ListTeamsFunc = func(ctx context.Context, filter fleet.TeamFilter, opt fleet.ListOptions) ([]*fleet.Team, error) {
|
||||
return []*fleet.Team{
|
||||
{
|
||||
ID: teamID1,
|
||||
Config: fleet.TeamConfig{
|
||||
Integrations: fleet.TeamIntegrations{
|
||||
GoogleCalendar: &fleet.TeamGoogleCalendarIntegration{
|
||||
Enable: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
policyID1 := uint(10)
|
||||
ds.GetCalendarPoliciesFunc = func(ctx context.Context, teamID uint) ([]fleet.PolicyCalendarData, error) {
|
||||
require.Equal(t, teamID1, teamID)
|
||||
return []fleet.PolicyCalendarData{
|
||||
{
|
||||
ID: policyID1,
|
||||
Name: "Policy 1",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
hostID1 := uint(100)
|
||||
hostID2 := uint(101)
|
||||
userEmail1 := "user@example.com"
|
||||
ds.GetTeamHostsPolicyMembershipsFunc = func(
|
||||
ctx context.Context, domain string, teamID uint, policyIDs []uint,
|
||||
) ([]fleet.HostPolicyMembershipData, error) {
|
||||
require.Equal(t, teamID1, teamID)
|
||||
require.Equal(t, []uint{policyID1}, policyIDs)
|
||||
return []fleet.HostPolicyMembershipData{
|
||||
{
|
||||
HostID: hostID1,
|
||||
Email: userEmail1,
|
||||
Passing: false,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
// Return an existing event, but for a different host
|
||||
eventTime := time.Now().Add(time.Hour)
|
||||
ds.GetHostCalendarEventByEmailFunc = func(ctx context.Context, email string) (*fleet.HostCalendarEvent, *fleet.CalendarEvent, error) {
|
||||
require.Equal(t, userEmail1, email)
|
||||
calEvent := &fleet.CalendarEvent{
|
||||
ID: 1,
|
||||
Email: email,
|
||||
StartTime: eventTime,
|
||||
EndTime: eventTime,
|
||||
}
|
||||
hcEvent := &fleet.HostCalendarEvent{
|
||||
ID: 1,
|
||||
HostID: hostID2,
|
||||
CalendarEventID: 1,
|
||||
WebhookStatus: fleet.CalendarWebhookStatusNone,
|
||||
}
|
||||
return hcEvent, calEvent, nil
|
||||
}
|
||||
|
||||
err := cronCalendarEvents(ctx, ds, logger)
|
||||
require.NoError(t, err)
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue