This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benji Visser <benji@093b.org>
- Loading branch information
Showing
7 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package agent | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/noqcks/xeol-agent/agent/inventory" | ||
"github.com/noqcks/xeol-agent/internal/config" | ||
) | ||
|
||
func TestPeriodicallyGetInventoryReport(t *testing.T) { | ||
cfg := &config.Application{ | ||
PollingIntervalSeconds: 1, | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Duration(cfg.PollingIntervalSeconds)*time.Second) | ||
defer cancel() | ||
|
||
reportTimes := []time.Time{} | ||
reportHandler := func(report inventory.Report, cfg *config.Application) error { | ||
reportTimes = append(reportTimes, time.Now()) | ||
return nil | ||
} | ||
|
||
getInventoryReportFunc := func(cfg *config.Application) (inventory.Report, error) { | ||
return inventory.Report{}, nil | ||
} | ||
startTime := time.Now() | ||
PeriodicallyGetInventoryReport(ctx, cfg, getInventoryReportFunc, reportHandler) | ||
|
||
if len(reportTimes) < 2 { | ||
t.Fatalf("Expected at least two reports, but got %d", len(reportTimes)) | ||
} | ||
|
||
firstInterval := reportTimes[0].Sub(startTime) | ||
if firstInterval >= time.Duration(cfg.PollingIntervalSeconds)*time.Second { | ||
t.Fatalf("Expected the first report to be immediate, but the interval was %v", firstInterval) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters