Skip to content

Commit

Permalink
Use addr.Suggest() instead of hardcoded ports for mock test server.
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfales authored and AMecea committed Jan 9, 2020
1 parent 2205bea commit fcbb5c3
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/sidecar/appclone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"os/exec"
"path"
"sigs.k8s.io/testing_frameworks/integration/addr"
)

var _ = Describe("Test RunCloneCommand cloning logic", func() {
Expand All @@ -36,11 +37,20 @@ var _ = Describe("Test RunCloneCommand cloning logic", func() {
// Normally, these are true k8s services, each listening on
// SidecarServerPort. Since we can't simulate that in unit tests, we put
// each "service" on its own port.
masterServiceAddr = fmt.Sprintf(":%d", serverPort)
healthyReplicasServiceAddr = ":8081"

masterServiceAddr string
healthyReplicasServiceAddr string
skipTruncatedDataTests = false
)

generateAddress := func() string {
port, host, err := addr.Suggest()
if err != nil {
panic("couldn't generate local address for fakeserver")
}
return fmt.Sprintf("%s:%d", host, port)
}

setupFakeDataDir := func() {
tempDataDir, err := ioutil.TempDir("", "mysql-operator-tests")
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -102,9 +112,12 @@ var _ = Describe("Test RunCloneCommand cloning logic", func() {
}

BeforeSuite(func() {
masterServiceAddr = generateAddress()
healthyReplicasServiceAddr = generateAddress()

cfg = &Config{
masterService: "localhost" + masterServiceAddr,
healthyReplicaCloneService: "localhost" + healthyReplicasServiceAddr,
masterService: masterServiceAddr,
healthyReplicaCloneService: healthyReplicasServiceAddr,
}

setupFakeDataDir()
Expand Down

0 comments on commit fcbb5c3

Please sign in to comment.