Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions pkg/armrpc/api/v1/armrequestcontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1

import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestFromARMRequest(t *testing.T) {

for _, tt := range headerTests {
t.Run(tt.desc, func(t *testing.T) {
req, err := getTestHTTPRequest("./testdata/armrpcheaders.json")
req, err := getTestHTTPRequest(t, "./testdata/armrpcheaders.json")
require.NoError(t, err)

if tt.refererUrl == "" {
Expand Down Expand Up @@ -162,7 +161,7 @@ func TestFromARMRequest_PrefersURLWhenRefererResourceDiffers(t *testing.T) {
}

func TestSystemData(t *testing.T) {
req, err := getTestHTTPRequest("./testdata/armrpcheaders.json")
req, err := getTestHTTPRequest(t, "./testdata/armrpcheaders.json")
require.NoError(t, err)
serviceCtx, err := FromARMRequest(req, "", LocationGlobal)
require.NoError(t, err)
Expand All @@ -179,11 +178,11 @@ func TestSystemData(t *testing.T) {

func TestFromContext(t *testing.T) {
t.Run("ARMRequestContext is injected", func(t *testing.T) {
req, err := getTestHTTPRequest("./testdata/armrpcheaders.json")
req, err := getTestHTTPRequest(t, "./testdata/armrpcheaders.json")
require.NoError(t, err)
serviceCtx, err := FromARMRequest(req, "", LocationGlobal)
require.NoError(t, err)
ctx := context.Background()
ctx := t.Context()
newCtx := WithARMRequestContext(ctx, serviceCtx)

sCtx := ARMRequestContextFromContext(newCtx)
Expand All @@ -193,7 +192,7 @@ func TestFromContext(t *testing.T) {

t.Run("ARMRequestContext is not injected", func(t *testing.T) {
require.Panics(t, func() {
ARMRequestContextFromContext(context.Background())
ARMRequestContextFromContext(t.Context())
})
})
}
Expand All @@ -214,7 +213,7 @@ func TestTopQueryParam(t *testing.T) {

for _, tt := range topQueryParamCases {
t.Run(tt.desc, func(t *testing.T) {
req, err := getTestHTTPRequest("./testdata/armrpcheaders.json")
req, err := getTestHTTPRequest(t, "./testdata/armrpcheaders.json")

q := req.URL.Query()
q.Add(tt.qpKey, tt.qpValue)
Expand All @@ -235,7 +234,7 @@ func TestTopQueryParam(t *testing.T) {
}
}

func getTestHTTPRequest(headerFile string) (*http.Request, error) {
func getTestHTTPRequest(t *testing.T, headerFile string) (*http.Request, error) {
jsonData, err := os.ReadFile(headerFile)
if err != nil {
return nil, err
Expand All @@ -246,7 +245,7 @@ func getTestHTTPRequest(headerFile string) (*http.Request, error) {
return nil, err
}

req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, strings.ToLower(parsed["Referer"]), nil)
req, err := http.NewRequestWithContext(t.Context(), http.MethodPut, strings.ToLower(parsed["Referer"]), nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/asyncoperation/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestUpdateResourceState(t *testing.T) {
defer mctrl.Finish()

databaseClient := database.NewMockClient(mctrl)
ctx := context.Background()
ctx := t.Context()

databaseClient.
EXPECT().
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/authentication/certvalidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestCertValidation(t *testing.T) {
Thumbprint: tc.fakeCertThumbprint,
}

ctx := context.Background()
ctx := t.Context()
log := logr.FromContextOrDiscard(ctx)
armCertMgr := NewArmCertManager(metadataEndpoint, log)
ArmCertStore.Store(tc.fakeCertThumbprint, cert)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestGetOperationStatusRun(t *testing.T) {
defer mctrl.Finish()

databaseClient := database.NewMockClient(mctrl)
ctx := context.Background()
ctx := t.Context()

rawDataModel := testutil.ReadFixture("operationstatus_datamodel.json")
osDataModel := &manager.Status{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/armrpc/frontend/defaultoperation/getresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestGetResourceRun(t *testing.T) {
defer mctrl.Finish()

databaseClient := database.NewMockClient(mctrl)
ctx := context.Background()
ctx := t.Context()

testResourceDataModel := &testDataModel{
Name: "ResourceName",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestListResourcesRun(t *testing.T) {
defer mctrl.Finish()

databaseClient := database.NewMockClient(mctrl)
ctx := context.Background()
ctx := t.Context()

testResourceDataModel := &testDataModel{
Name: "ResourceName",
Expand Down
18 changes: 9 additions & 9 deletions pkg/cli/cmd/install/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func Test_Run(t *testing.T) {
outputMock := &output.MockOutput{}
factory, k8sMock, postInstallWrites := expectDefaultGroupAndEnvCreation(t, ctrl)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -178,7 +178,7 @@ func Test_Run(t *testing.T) {
helmMock := helm.NewMockInterface(ctrl)
outputMock := &output.MockOutput{}

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -223,7 +223,7 @@ func Test_Run(t *testing.T) {
k8sMock := cli_kubernetes.NewMockInterface(ctrl)
factory := &connections.MockFactory{ApplicationsManagementClient: mgmtMock}

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -277,7 +277,7 @@ func Test_Run(t *testing.T) {
outputMock := &output.MockOutput{}
factory, k8sMock, postInstallWrites := expectDefaultGroupAndEnvCreation(t, ctrl)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -323,7 +323,7 @@ func Test_Run(t *testing.T) {
outputMock := &output.MockOutput{}
factory, k8sMock, postInstallWrites := expectDefaultGroupAndEnvCreation(t, ctrl)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -365,7 +365,7 @@ func Test_Run(t *testing.T) {
outputMock := &output.MockOutput{}
factory, k8sMock, postInstallWrites := expectDefaultGroupAndEnvCreation(t, ctrl)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -408,7 +408,7 @@ func Test_Run(t *testing.T) {
outputMock := &output.MockOutput{}
factory, k8sMock, postInstallWrites := expectDefaultGroupAndEnvCreation(t, ctrl)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -466,7 +466,7 @@ func Test_Run(t *testing.T) {
// GetEnvironment / CreateOrUpdateEnvironment must not be called: the runner should bail out
// as soon as the resource group create fails.

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -520,7 +520,7 @@ func Test_Run(t *testing.T) {
Return(boom).
Times(1)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down
14 changes: 7 additions & 7 deletions pkg/cli/cmd/uninstall/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Test_Run(t *testing.T) {
outputMock := &output.MockOutput{}
promptMock := prompt.NewMockInterface(ctrl)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -124,7 +124,7 @@ func Test_Run(t *testing.T) {
outputMock := &output.MockOutput{}
promptMock := prompt.NewMockInterface(ctrl)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -157,7 +157,7 @@ func Test_Run(t *testing.T) {
promptMock := prompt.NewMockInterface(ctrl)
connFactory := &connections.MockFactory{ApplicationsManagementClient: appManagementClient}

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -276,7 +276,7 @@ func Test_Run(t *testing.T) {
promptMock := prompt.NewMockInterface(ctrl)
connFactory := &connections.MockFactory{ApplicationsManagementClient: appManagementClient}

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -396,7 +396,7 @@ func Test_Run(t *testing.T) {
outputMock := &output.MockOutput{}
promptMock := prompt.NewMockInterface(ctrl)

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -437,7 +437,7 @@ func Test_Run(t *testing.T) {
helmMock := helm.NewMockInterface(ctrl)
outputMock := &output.MockOutput{}

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down Expand Up @@ -484,7 +484,7 @@ func Test_Run(t *testing.T) {
envErr := errors.New("failed to connect")
factory := &errorApplicationsFactory{MockFactory: &connections.MockFactory{}, err: envErr}

ctx := context.Background()
ctx := t.Context()
runner := &Runner{
Helm: helmMock,
Output: outputMock,
Expand Down
Loading
Loading