Skip to content

Commit

Permalink
r/image: adding a context as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Aug 8, 2023
1 parent a727225 commit e37e1da
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/services/compute/image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log"
"testing"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
Expand Down Expand Up @@ -209,6 +210,12 @@ func (ImageResource) generalizeVirtualMachine(data acceptance.TestData) func(con
return err
}

if _, ok := ctx.Deadline(); !ok {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, 15*time.Minute)
defer cancel()
}

// these are nested in a Set in the Legacy VM resource, simpler to compute them
userName := fmt.Sprintf("testadmin%d", data.RandomInteger)
password := fmt.Sprintf("Password1234!%d", data.RandomInteger)
Expand Down Expand Up @@ -307,6 +314,11 @@ func (ImageResource) virtualMachineExists(ctx context.Context, client *clients.C
return err
}

if _, ok := ctx.Deadline(); !ok {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, 15*time.Minute)
defer cancel()
}
resp, err := client.Compute.VirtualMachinesClient.Get(ctx, *id, virtualmachines.DefaultGetOperationOptions())
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
Expand Down

0 comments on commit e37e1da

Please sign in to comment.