-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from euanh/test-refactor
Refactor duplicated setup and verification code
- Loading branch information
Showing
12 changed files
with
259 additions
and
1,120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,29 @@ | ||
package standard | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func testCreateAppServiceContextRoot(t *testing.T) { | ||
appHost := "demo-context-root.test" | ||
contextRoot := "/app" | ||
appServiceID, _, err := testCluster.Exec(manager, []string{ | ||
"docker", | ||
"service", | ||
"create", | ||
"-q", | ||
"--label", | ||
"app=demo-test", | ||
"--network", | ||
testNetName, | ||
"--label", | ||
"com.docker.lb.hosts=" + appHost, | ||
"--label", | ||
"com.docker.lb.port=8080", | ||
"--label", | ||
"com.docker.lb.context_root=" + contextRoot, | ||
"--label", | ||
"com.docker.lb.context_root_rewrite=true", | ||
testAppImage, | ||
}, true, nil) | ||
appServiceID, err := createService( | ||
"--label", "app=demo-test", | ||
"--network", testNetName, | ||
"--label", "com.docker.lb.hosts="+appHost, | ||
"--label", "com.docker.lb.port=8080", | ||
"--label", "com.docker.lb.context_root="+contextRoot, | ||
"--label", "com.docker.lb.context_root_rewrite=true", | ||
testAppImage) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer testCluster.RemoveService(appServiceID) | ||
|
||
status, _, err := testCluster.Exec(manager, []string{ | ||
"docker", | ||
"service", | ||
"ls", | ||
"-q", | ||
"-f", | ||
"id=" + appServiceID, | ||
}, true, nil) | ||
resp, err := curl("-sSIL", "http://"+appHost+contextRoot) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if strings.Index(appServiceID, status) == -1 { | ||
t.Fatal("unable to find app service") | ||
} | ||
defer testCluster.RemoveService(appServiceID) | ||
|
||
if status, _, err := testCluster.Exec(manager, []string{ | ||
"docker", | ||
"pull", | ||
testCurlImage, | ||
}, true, nil); err != nil { | ||
t.Fatal(status) | ||
} | ||
|
||
command := []string{ | ||
"docker", | ||
"run", | ||
"--net=host", | ||
"-v", | ||
testHostsFile + ":/etc/hosts", | ||
"--entrypoint", | ||
"curl", | ||
testCurlImage, | ||
"-sSIL", | ||
"--fail", | ||
"http://" + appHost + contextRoot, | ||
} | ||
|
||
successChan := make(chan string, 1) | ||
go func() { | ||
for { | ||
resp, err := commonManager.WaitForExec(command, serviceWaitTimeout) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
successChan <- resp | ||
} | ||
}() | ||
select { | ||
case resp := <-successChan: | ||
t.Logf("context root routing successful: %s", resp) | ||
case <-time.After(serviceTestTimeout): | ||
t.Fatal("timeout waiting on context root") | ||
} | ||
t.Logf("context root routing successful: %s", resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,25 @@ | ||
package standard | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func testCreateAppServiceDefaultBackend(t *testing.T) { | ||
netName := "demo-default-backend-net" | ||
createNet(netName, t) | ||
appServiceID, _, err := testCluster.Exec(manager, []string{ | ||
"docker", | ||
"service", | ||
"create", | ||
"-q", | ||
"--network", | ||
netName, | ||
"--label", | ||
"com.docker.lb.default_backend=true", | ||
"--label", | ||
"com.docker.lb.port=8080", | ||
testAppImage, | ||
}, true, nil) | ||
appServiceID, err := createService( | ||
"--network", netName, | ||
"--label", "com.docker.lb.default_backend=true", | ||
"--label", "com.docker.lb.port=8080", | ||
testAppImage) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer testCluster.RemoveService(appServiceID) | ||
|
||
status, _, err := testCluster.Exec(manager, []string{ | ||
"docker", | ||
"service", | ||
"ls", | ||
"-q", | ||
"-f", | ||
"id=" + appServiceID, | ||
}, true, nil) | ||
resp, err := curl("-sSIL", "http://anyhost.test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if strings.Index(appServiceID, status) == -1 { | ||
t.Fatal("unable to find app service") | ||
} | ||
defer testCluster.RemoveService(appServiceID) | ||
|
||
if status, _, err := testCluster.Exec(manager, []string{ | ||
"docker", | ||
"pull", | ||
testCurlImage, | ||
}, true, nil); err != nil { | ||
t.Fatal(status) | ||
} | ||
|
||
command := []string{ | ||
"docker", | ||
"run", | ||
"--net=host", | ||
"-v", | ||
testHostsFile + ":/etc/hosts", | ||
"--entrypoint", | ||
"curl", | ||
testCurlImage, | ||
"-sSIL", | ||
"--fail", | ||
"http://anyhost.test", | ||
} | ||
|
||
successChan := make(chan string, 1) | ||
go func() { | ||
for { | ||
resp, err := commonManager.WaitForExec(command, serviceWaitTimeout) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
successChan <- resp | ||
} | ||
}() | ||
select { | ||
case resp := <-successChan: | ||
t.Logf("service configured for default backend successfully: %s", resp) | ||
case <-time.After(serviceTestTimeout): | ||
t.Fatal("timeout waiting on default backend") | ||
} | ||
t.Logf("service configured for default backend successfully: %s", resp) | ||
} |
Oops, something went wrong.