-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* replace dque with pdque * add test * add pdque into cnspec directly * clean up * restore go.mod * go mod tidy * fix license * clean up * clean up * better concurrency test * refactor with require.NoError * improve tests * clean up * go fmt * test fix? * fix tests in github action * test tests * test tests * go fmt * test tests * clean up * let New create the directory
- Loading branch information
1 parent
746b03e
commit ce1a460
Showing
6 changed files
with
800 additions
and
22 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
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,71 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package scan | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" | ||
) | ||
|
||
func TestDiskQueueClient_EnqueueDequeue(t *testing.T) { | ||
tempDir, err := os.MkdirTemp("", "testdir") | ||
if err != nil { | ||
t.Fatalf("Failed to create temp dir: %v", err) | ||
} | ||
defer os.RemoveAll(tempDir) // Clean up | ||
|
||
// Update the configuration to use the temporary directory | ||
testConfig := defaultDqueConfig | ||
testConfig.dir = tempDir | ||
|
||
completionChannel := make(chan struct{}, 50) // Channel to signal job completion | ||
|
||
handler := func(job *Job) { | ||
completionChannel <- struct{}{} // Signal completion | ||
} | ||
|
||
client, err := newDqueClient(testConfig, handler) | ||
if err != nil { | ||
t.Fatalf("Failed to create diskQueueClient: %v", err) | ||
} | ||
defer client.Stop() | ||
|
||
// Test Enqueue | ||
testJob := &Job{ | ||
Inventory: &inventory.Inventory{ | ||
Spec: &inventory.InventorySpec{ | ||
Assets: []*inventory.Asset{ | ||
{ | ||
Connections: []*inventory.Config{ | ||
{ | ||
Type: "k8s", | ||
Options: map[string]string{ | ||
"path": "./testdata/2pods.yaml", | ||
}, | ||
Discover: &inventory.Discovery{ | ||
Targets: []string{"auto"}, | ||
}, | ||
}, | ||
}, | ||
ManagedBy: "mondoo-operator-123", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for i := 0; i < 50; i++ { | ||
client.Channel() <- *testJob | ||
} | ||
|
||
for i := 0; i < 50; i++ { | ||
<-completionChannel | ||
} | ||
|
||
// Verify that all jobs have been processed | ||
if len(completionChannel) != 0 { | ||
t.Errorf("Expected handler to be called 50 times, but was called %d times", 50-len(completionChannel)) | ||
} | ||
} |
Oops, something went wrong.