-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow openfga test container to be reused (#172)
* feat: allow openfga test container to be reused Signed-off-by: Sarah Funkhouser <[email protected]> * allow setting cpu and memory a well Signed-off-by: Sarah Funkhouser <[email protected]> --------- Signed-off-by: Sarah Funkhouser <[email protected]>
- Loading branch information
1 parent
b42133c
commit b0ac80f
Showing
2 changed files
with
90 additions
and
3 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,46 @@ | ||
package testutils | ||
|
||
import ( | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/testcontainers/testcontainers-go" | ||
) | ||
|
||
const ( | ||
testcontainerName = "tc-openfga" | ||
) | ||
|
||
// Customizer type represents a container customizer for transferring state from the options to the container | ||
type Customizer struct { | ||
reuse bool | ||
name string | ||
memory int64 | ||
cpu int64 | ||
} | ||
|
||
// Customize satisfies the ContainerCustomizer interface | ||
func (c Customizer) Customize(req *testcontainers.GenericContainerRequest) error { | ||
req.Reuse = c.reuse | ||
req.Name = c.name | ||
|
||
req.HostConfigModifier = func(config *container.HostConfig) { | ||
if c.memory > 0 { | ||
config.Resources.Memory = c.memory | ||
} | ||
|
||
if c.cpu > 0 { | ||
config.Resources.CPUQuota = c.cpu | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// WithCustomizer function option to use the customizer | ||
func WithCustomizer(reuse bool, name string, memory, cpu int64) testcontainers.ContainerCustomizer { | ||
return Customizer{ | ||
reuse: reuse, | ||
name: name, | ||
memory: memory, | ||
cpu: cpu, | ||
} | ||
} |