diff --git a/testcontainers-c/testcontainers-c.go b/testcontainers-c/testcontainers-c.go index 1f1db41..a2b185a 100644 --- a/testcontainers-c/testcontainers-c.go +++ b/testcontainers-c/testcontainers-c.go @@ -9,9 +9,12 @@ import ( "io" "net/http" "strconv" + "strings" "github.com/docker/go-connections/nat" "github.com/testcontainers/testcontainers-go" + + uuid "github.com/google/uuid" compose "github.com/testcontainers/testcontainers-go/modules/compose" "github.com/testcontainers/testcontainers-go/wait" ) @@ -19,7 +22,7 @@ import ( var containerRequests []*testcontainers.ContainerRequest var containers []*testcontainers.Container var customizers map[int][]*testcontainers.CustomizeRequestOption -var composeGroups []*compose.ComposeStack +var composeGroups []compose.ComposeStack // Creates Unique container request and returns its ID // @@ -45,16 +48,16 @@ func tc_run_container(requestID int) (id int, ok bool, errstr *C.char) { //export tc_new_docker_compose func tc_new_docker_compose(path *C.cchar_t) (id int, ok bool, errstr *C.char) { - compose, err := compose.NewDockerCompose(C.GoString(path)) + composeFilePaths := []string{C.GoString(path)} + identifier := strings.ToLower(uuid.New().String()) + + compose := compose.NewLocalDockerCompose(composeFilePaths, identifier) composeId := -1 if compose != nil { // We register the container even if the run failed composeGroups = append(composeGroups, &compose) composeId = len(containers) - 1 } - if err != nil { - return -1, ok, ToCString(err) - } return composeId, ok, nil } @@ -96,7 +99,7 @@ func tc_terminate_container(containerID int) *C.char { //export tc_terminate_compose func tc_terminate_compose(composeID int) *C.char { ctx := context.Background() - composeInstance := *composeGroups[composeID] + composeInstance := composeGroups[composeID] res := composeInstance.Down(ctx, compose.RemoveOrphans(true), compose.RemoveImagesLocal) return ToCString(res) }