-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
353f4b9
commit bdedcb4
Showing
4 changed files
with
70 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package assert | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/stackrox/collector/integration-tests/pkg/collector" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/stackrox/collector/integration-tests/pkg/types" | ||
) | ||
|
||
func AssertExternalIps(t *testing.T, enable bool, collectorIP string) { | ||
AssertRepeated(t, func() bool { | ||
body, err := collector.IntrospectionQuery(collectorIP, "/state/config") | ||
assert.NoError(t, err) | ||
var response types.RuntimeConfig | ||
err = json.Unmarshal(body, &response) | ||
assert.NoError(t, err) | ||
|
||
return response.Networking.ExternalIps.Enable == enable | ||
}) | ||
} | ||
|
||
func AssertNoRuntimeConfig(t *testing.T, collectorIP string) { | ||
AssertRepeated(t, func() bool { | ||
body, err := collector.IntrospectionQuery(collectorIP, "/state/config") | ||
assert.NoError(t, err) | ||
return strings.TrimSpace(string(body)) == "{}" | ||
}) | ||
} | ||
|
||
func AssertRepeated(t *testing.T, condition func() bool) { | ||
tick := time.NewTicker(1 * time.Second) | ||
timer := time.After(3 * time.Minute) | ||
|
||
for { | ||
select { | ||
case <-tick.C: | ||
if condition() { | ||
// Condition has been met | ||
return | ||
} | ||
|
||
case <-timer: | ||
// TODO: This message should be passed in rather than hard coded here | ||
t.Log("Timeout reached: Runtime configuration was not updated") | ||
t.FailNow() | ||
} | ||
} | ||
} |
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