Skip to content

Commit

Permalink
fix cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
noamcattan committed Oct 13, 2024
1 parent c3ffc3a commit 7f533a4
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions atlasaction/gitlab_ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path/filepath"
"strconv"
"sync"
"testing"
)

Expand Down Expand Up @@ -87,22 +88,26 @@ func newMockHandler(dir string) http.Handler {
}

func TestGitlabCI(t *testing.T) {
var srv *httptest.Server
cleanup := func() {
if srv != nil {
srv.Close()
var (
servers = make([]*httptest.Server, 0)
lock = &sync.Mutex{}
)
defer func() {
for _, server := range servers {
server.Close()
}
}
defer cleanup()
}()
testscript.Run(t, testscript.Params{
Dir: "testdata/gitlab",
Setup: func(env *testscript.Env) error {
commentsDir := filepath.Join(env.WorkDir, "comments")
srv := httptest.NewServer(newMockHandler(commentsDir))
if err := os.Mkdir(commentsDir, os.ModePerm); err != nil {
return err
}
cleanup()
srv = httptest.NewServer(newMockHandler(commentsDir))
lock.Lock()
servers = append(servers, srv)
lock.Unlock()
env.Setenv("GITLAB_CI", "true")
env.Setenv("CI_PROJECT_ID", "1")
env.Setenv("CI_API_V4_URL", srv.URL)
Expand Down

0 comments on commit 7f533a4

Please sign in to comment.