Skip to content

Commit

Permalink
Save progress
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed Oct 31, 2023
1 parent 735d52e commit b6ef741
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions testcontainers-c/testcontainers-c.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ 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"
)

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
//
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b6ef741

Please sign in to comment.