Skip to content

Commit e0fa633

Browse files
committed
add AfterCaptureHook to fix Test_Deploy
1 parent 44913e9 commit e0fa633

9 files changed

+10713
-397
lines changed

β€Žcore/testing_recorder.goβ€Ž

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ func cassetteResponseFilter(i *cassette.Interaction) error {
5050
}
5151

5252
const (
53-
windowDockerEngine = "//./pipe/docker_engine"
54-
unixDockerEngine = "/var/run/docker.sock"
53+
windowDockerEngine = "//./pipe/docker_engine"
54+
unixDockerEngine = "/var/run/docker.sock"
55+
escapedUnixDockerEngine = "%2Fvar%2Frun%2Fdocker.sock"
5556
)
5657

5758
func cassetteMatcher(r *http.Request, i cassette.Request) bool {
@@ -124,6 +125,16 @@ func customS3Matcher(r *http.Request, i cassette.Request) bool {
124125
actualURL.RawQuery == expectedURL.RawQuery
125126
}
126127

128+
func unescapeDockerURL(i *cassette.Interaction) error {
129+
if strings.HasPrefix(i.Request.URL, "http://"+escapedUnixDockerEngine) {
130+
i.Request.URL = regexp.MustCompile(`http://`+escapedUnixDockerEngine+`(.+)?`).ReplaceAllString(
131+
i.Request.URL,
132+
"http://"+unixDockerEngine+"${1}")
133+
}
134+
135+
return nil
136+
}
137+
127138
// getHTTPRecoder creates a new httpClient that records all HTTP requests in a cassette.
128139
// This cassette is then replayed whenever tests are executed again. This means that once the
129140
// requests are recorded in the cassette, no more real HTTP request must be made to run the tests.
@@ -148,6 +159,10 @@ func getHTTPRecoder(t *testing.T, update bool) (client *http.Client, cleanup fun
148159
return nil, nil, err
149160
}
150161

162+
// Starting with v3, go-vcr now calls net/url.Parse to build the interaction which results in an error for escaped
163+
// Docker URLs on Test_Deploy (container), so we need to unescape these paths on this step.
164+
r.AddHook(unescapeDockerURL, recorder.AfterCaptureHook)
165+
151166
// Add a filter which removes Authorization headers from all requests:
152167
r.AddHook(cassetteRequestFilter, recorder.BeforeSaveHook)
153168

β€Žinternal/namespaces/container/v1beta1/testdata/test-deploy-app-name-deduced-from-path.cassette.yamlβ€Ž

Lines changed: 3848 additions & 72 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲
2-
πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️
3-
Task 4 "Building image" failed: could not build image: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=rg.fr-par.scw.cloud%2Ffuncscwappclitctnrdeployfpdmrsxdcp%2Fapp-cli-t-ctnr-deploy-fp%3Alatest&target=&ulimits=null&version=": parse "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=rg.fr-par.scw.cloud%2Ffuncscwappclitctnrdeployfpdmrsxdcp%2Fapp-cli-t-ctnr-deploy-fp%3Alatest&target=&ulimits=null&version=": invalid URL escape "%2F"
4-
πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯
5-
{
6-
"error": "task 4 \"Building image\" failed: could not build image: error during connect: Post \"http://%2Fvar%2Frun%2Fdocker.sock/v1.47/build?buildargs=null\u0026cachefrom=null\u0026cgroupparent=\u0026cpuperiod=0\u0026cpuquota=0\u0026cpusetcpus=\u0026cpusetmems=\u0026cpushares=0\u0026dockerfile=Dockerfile\u0026labels=null\u0026memory=0\u0026memswap=0\u0026networkmode=\u0026rm=0\u0026shmsize=0\u0026t=rg.fr-par.scw.cloud%2Ffuncscwappclitctnrdeployfpdmrsxdcp%2Fapp-cli-t-ctnr-deploy-fp%3Alatest\u0026target=\u0026ulimits=null\u0026version=\": parse \"http://%2Fvar%2Frun%2Fdocker.sock/v1.47/build?buildargs=null\u0026cachefrom=null\u0026cgroupparent=\u0026cpuperiod=0\u0026cpuquota=0\u0026cpusetcpus=\u0026cpusetmems=\u0026cpushares=0\u0026dockerfile=Dockerfile\u0026labels=null\u0026memory=0\u0026memswap=0\u0026networkmode=\u0026rm=0\u0026shmsize=0\u0026t=rg.fr-par.scw.cloud%2Ffuncscwappclitctnrdeployfpdmrsxdcp%2Fapp-cli-t-ctnr-deploy-fp%3Alatest\u0026target=\u0026ulimits=null\u0026version=\": invalid URL escape \"%2F\""
7-
}
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3+
Your application is now available at https://appclitctnrdeployfp95ivlueu-app-cli-t-ctnr-deploy-fp.functions.fnc.fr-par.scw.cloud
4+
5+
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
6+
"Your application is now available at https://appclitctnrdeployfp95ivlueu-app-cli-t-ctnr-deploy-fp.functions.fnc.fr-par.scw.cloud\n"

β€Žinternal/namespaces/container/v1beta1/testdata/test-deploy-build-args.cassette.yamlβ€Ž

Lines changed: 870 additions & 85 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
🎲🎲🎲 EXIT CODE: 1 🎲🎲🎲
2-
πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️
3-
Task 4 "Building image" failed: could not build image: error during connect: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/build?buildargs=%7B%22TEST%22%3A%22thisisatest%22%7D&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=rg.fr-par.scw.cloud%2Ffuncscwclitctnrdeploybat2mhdji3%2Fcli-t-ctnr-deploy-ba%3Alatest&target=&ulimits=null&version=": parse "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/build?buildargs=%7B%22TEST%22%3A%22thisisatest%22%7D&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=rg.fr-par.scw.cloud%2Ffuncscwclitctnrdeploybat2mhdji3%2Fcli-t-ctnr-deploy-ba%3Alatest&target=&ulimits=null&version=": invalid URL escape "%2F"
4-
πŸŸ₯πŸŸ₯πŸŸ₯ JSON STDERR πŸŸ₯πŸŸ₯πŸŸ₯
5-
{
6-
"error": "task 4 \"Building image\" failed: could not build image: error during connect: Post \"http://%2Fvar%2Frun%2Fdocker.sock/v1.47/build?buildargs=%7B%22TEST%22%3A%22thisisatest%22%7D\u0026cachefrom=null\u0026cgroupparent=\u0026cpuperiod=0\u0026cpuquota=0\u0026cpusetcpus=\u0026cpusetmems=\u0026cpushares=0\u0026dockerfile=Dockerfile\u0026labels=null\u0026memory=0\u0026memswap=0\u0026networkmode=\u0026rm=0\u0026shmsize=0\u0026t=rg.fr-par.scw.cloud%2Ffuncscwclitctnrdeploybat2mhdji3%2Fcli-t-ctnr-deploy-ba%3Alatest\u0026target=\u0026ulimits=null\u0026version=\": parse \"http://%2Fvar%2Frun%2Fdocker.sock/v1.47/build?buildargs=%7B%22TEST%22%3A%22thisisatest%22%7D\u0026cachefrom=null\u0026cgroupparent=\u0026cpuperiod=0\u0026cpuquota=0\u0026cpusetcpus=\u0026cpusetmems=\u0026cpushares=0\u0026dockerfile=Dockerfile\u0026labels=null\u0026memory=0\u0026memswap=0\u0026networkmode=\u0026rm=0\u0026shmsize=0\u0026t=rg.fr-par.scw.cloud%2Ffuncscwclitctnrdeploybat2mhdji3%2Fcli-t-ctnr-deploy-ba%3Alatest\u0026target=\u0026ulimits=null\u0026version=\": invalid URL escape \"%2F\""
7-
}
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3+
Your application is now available at https://clitctnrdeploybajqohkyqb-cli-t-ctnr-deploy-ba.functions.fnc.fr-par.scw.cloud
4+
5+
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
6+
"Your application is now available at https://clitctnrdeploybajqohkyqb-cli-t-ctnr-deploy-ba.functions.fnc.fr-par.scw.cloud\n"

0 commit comments

Comments
Β (0)