Skip to content

Commit

Permalink
Build and start the mock server once
Browse files Browse the repository at this point in the history
  • Loading branch information
kardolus committed Nov 1, 2023
1 parent ba65482 commit de2ec8e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"io"
"log"
"os"
"os/exec"
"path"
"strconv"
"strings"
"sync"
"testing"
"time"

Expand All @@ -28,6 +30,8 @@ const (
serviceURL = "http://0.0.0.0"
)

var once sync.Once

func TestIntegration(t *testing.T) {
defer gexec.CleanupBuildArtifacts()
spec.Run(t, "Integration Tests", testIntegration, spec.Report(report.Terminal{}))
Expand Down Expand Up @@ -165,14 +169,21 @@ func testIntegration(t *testing.T, when spec.G, it spec.S) {
)

it.Before(func() {
SetDefaultEventuallyTimeout(5 * time.Second)
once.Do(func() {
SetDefaultEventuallyTimeout(10 * time.Second)

log.Println("Building binary...")
Expect(buildBinary()).To(Succeed())
log.Println("Binary built successfully!")

Expect(buildBinary()).To(Succeed())
Expect(runMockServer()).To(Succeed())
log.Println("Starting mock server...")
Expect(runMockServer()).To(Succeed())
log.Println("Mock server started!")

Eventually(func() (string, error) {
return curl(fmt.Sprintf("%s/ping", serviceURL))
}).Should(ContainSubstring("pong"))
Eventually(func() (string, error) {
return curl(fmt.Sprintf("%s/ping", serviceURL))
}).Should(ContainSubstring("pong"))
})

homeDir, err = os.MkdirTemp("", "mockHome")
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit de2ec8e

Please sign in to comment.