summaryrefslogtreecommitdiff
path: root/client/httpclient_test.go
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2020-09-19 03:34:49 -0700
committerStan Hu <stanhu@gmail.com>2020-09-19 14:00:45 -0700
commit0590d9198f653ff2170e0f26790056bef4f056fe (patch)
treedc0d68866ea16ba4f74d441c3aa2048b12fb9e95 /client/httpclient_test.go
parentf100e7e83943b3bb5db232f5bf79a616fdba88f1 (diff)
downloadgitlab-shell-sh-extract-context-from-env.tar.gz
Make it possible to propagate correlation ID across processessh-extract-context-from-env
Previously, gitlab-shell did not pass a context through the application. Correlation IDs were generated down the call stack, since we don't pass the context around from the start execution. This has several potential downsides: 1. It's easier for programming mistakes to be made in future which lead to multiple correlation IDs being generated for a single request. 2. Correlation IDs cannot be passed in from upstream requests 3. Other advantages of context passing, such as distributed tracing is not possible. This commit changes the behavior: 1. Extract the correlation ID from the environment at the start of the application. 2. If no correlation ID exists, generate a random one. 3. Pass the correlation ID to the GitLabNet API requests. This change also enables other clients of GitLabNet (e.g. Gitaly) to pass along the correlation ID in the internal API requests (https://gitlab.com/gitlab-org/gitaly/-/issues/2725). Fixes https://gitlab.com/gitlab-org/gitlab-shell/-/issues/474
Diffstat (limited to 'client/httpclient_test.go')
-rw-r--r--client/httpclient_test.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/client/httpclient_test.go b/client/httpclient_test.go
index fce0cd5..97e1384 100644
--- a/client/httpclient_test.go
+++ b/client/httpclient_test.go
@@ -1,6 +1,7 @@
package client
import (
+ "context"
"encoding/base64"
"fmt"
"io/ioutil"
@@ -51,11 +52,11 @@ func TestBasicAuthSettings(t *testing.T) {
client, cleanup := setup(t, username, password, requests)
defer cleanup()
- response, err := client.Get("/get_endpoint")
+ response, err := client.Get(context.Background(), "/get_endpoint")
require.NoError(t, err)
testBasicAuthHeaders(t, response)
- response, err = client.Post("/post_endpoint", nil)
+ response, err = client.Post(context.Background(), "/post_endpoint", nil)
require.NoError(t, err)
testBasicAuthHeaders(t, response)
}
@@ -89,7 +90,7 @@ func TestEmptyBasicAuthSettings(t *testing.T) {
client, cleanup := setup(t, "", "", requests)
defer cleanup()
- _, err := client.Get("/empty_basic_auth")
+ _, err := client.Get(context.Background(), "/empty_basic_auth")
require.NoError(t, err)
}