Skip to content

Commit

Permalink
Fixes for go test ./... -count=2
Browse files Browse the repository at this point in the history
When tests are run multiple times the state of package level variables are retained. Made some adjustments so the tests still pass in this scenario.
  • Loading branch information
coreyogburn committed Aug 27, 2024
1 parent fcdb762 commit 2be6cf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/modules/detections/ai_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/fs"
"sort"
"testing"
"time"

"github.com/apex/log"
"github.com/security-onion-solutions/securityonion-soc/model"
Expand Down Expand Up @@ -55,6 +56,8 @@ func TestRefreshAiSummaries(t *testing.T) {

logger := log.WithField("test", true)

lastSuccessfulAiUpdate = time.Time{}

err := RefreshAiSummaries(loader, model.SigLangSigma, &isRunning, "baseRepoFolder", repo, branch, logger, iom)
assert.NoError(t, err)
}
3 changes: 3 additions & 0 deletions server/modules/detections/detengine_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,16 @@ func TestCheckTemplate(t *testing.T) {
detStore.EXPECT().DoesTemplateExist(ctx, "so-detection").Return(false, nil)
detStore.EXPECT().DoesTemplateExist(ctx, "so-detection").Return(true, nil).Times(1)

templateFound = false

results := []bool{}
for i := 0; i < 10; i++ {
result := CheckTemplate(ctx, detStore)
results = append(results, result)
}

assert.Equal(t, []bool{false, true, true, true, true, true, true, true, true, true}, results)
assert.Equal(t, true, templateFound)
}

func TestUpdateRepos(t *testing.T) {
Expand Down

0 comments on commit 2be6cf4

Please sign in to comment.