Skip to content
Merged
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
2 changes: 1 addition & 1 deletion eng/pipelines/mgmt-auto-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ stages:

- task: GoTool@0
inputs:
version: '1.19'
version: '1.20'

- task: ShellScript@2
inputs:
Expand Down
18 changes: 13 additions & 5 deletions eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,27 @@ stages:
Linux_Go118:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.18.5'
go.version: '1.18.10'
Windows_Go118:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.18.5'
go.version: '1.18.10'
Linux_Go119:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.19'
go.version: '1.19.5'
Windows_Go119:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.19'
go.version: '1.19.5'
Linux_Go120:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.20'
Windows_Go120:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.20'
pool:
name: $(pool.name)
vmImage: $(image.name)
Expand Down Expand Up @@ -63,7 +71,7 @@ stages:
steps:
- task: GoTool@0
inputs:
version: '1.19'
version: '1.20'
displayName: "Select Go Version"

- template: ../steps/create-go-workspace.yml
Expand Down
16 changes: 12 additions & 4 deletions eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,27 @@ stages:
Linux_Go118:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.18.5'
go.version: '1.18.10'
Windows_Go118:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.18.5'
go.version: '1.18.10'
Linux_Go119:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.19'
Windows_Go119:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.19'
go.version: '1.19'
Linux_Go120:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.20'
Windows_Go120:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.20'
generate.bom: true
pool:
name: $(pool.name)
Expand Down Expand Up @@ -141,7 +149,7 @@ stages:

- task: GoTool@0
inputs:
version: '1.19'
version: '1.20'
displayName: "Select Go Version"

- template: ../steps/create-go-workspace.yml
Expand Down
18 changes: 13 additions & 5 deletions eng/pipelines/templates/jobs/archetype-sdk-eng-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,27 @@ stages:
Linux_Go118:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.18.5'
go.version: '1.18.10'
Windows_Go118:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.18.5'
go.version: '1.18.10'
Linux_Go119:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.19'
go.version: '1.19.5'
Windows_Go119:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.19'
go.version: '1.19.5'
Linux_Go120:
pool.name: azsdk-pool-mms-ubuntu-2004-general
image.name: MMSUbuntu20.04
go.version: '1.20'
Windows_Go120:
pool.name: azsdk-pool-mms-win-2022-general
image.name: MMS2022
go.version: '1.20'
generate.bom: true
pool:
name: $(pool.name)
Expand Down Expand Up @@ -79,7 +87,7 @@ stages:

- task: GoTool@0
inputs:
version: '1.19'
version: '1.20'
displayName: "Select Go Version"

- template: ../steps/create-go-workspace.yml
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/templates/jobs/mgmt-mock-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
displayName: 'Install autorest'
- task: GoTool@0
inputs:
version: '1.19'
version: '1.20'
displayName: "Select Go Version"

- template: /eng/pipelines/templates/steps/create-go-workspace.yml
Expand Down
4 changes: 3 additions & 1 deletion eng/pipelines/templates/stages/platform-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
}
},
"GoVersion": [
"1.18.2"
"1.18.10",
"1.19.5",
"1.20"
]
}
}
2 changes: 1 addition & 1 deletion eng/pipelines/templates/variables/globals.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variables:
GoLintCLIVersion: 'v1.48.0'
GoLintCLIVersion: 'v1.51.1'
Package.EnableSBOMSigning: true
# Enable go native component governance detection
# https://docs.opensource.microsoft.com/tools/cg/index.html
Expand Down
6 changes: 3 additions & 3 deletions eng/scripts/automation_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ outputFile="$(realpath $outputFile)"
echo "output json file: $outputFile"

TMPDIR="/tmp"
if [ ! "$(go version | awk '{print $3}' | cut -c 3-6)" = "1.19" ]
if [ ! "$(go version | awk '{print $3}' | cut -c 3-6)" = "1.20" ]
then
wget https://golang.org/dl/go1.19.linux-amd64.tar.gz
tar -C $TMPDIR -xzf go1.19.linux-amd64.tar.gz
wget https://golang.org/dl/go1.20.linux-amd64.tar.gz
tar -C $TMPDIR -xzf go1.20.linux-amd64.tar.gz
export GOROOT=$TMPDIR/go
export PATH=$GOROOT/bin:$PATH
fi
Expand Down
2 changes: 1 addition & 1 deletion sdk/resourcemanager/internal/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0
github.com/stretchr/testify v1.7.0
)
Expand Down
4 changes: 2 additions & 2 deletions sdk/resourcemanager/internal/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.0 h1:Ut0ZGdOwJDw0npYEg+TLlPls3
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0 h1:Yoicul8bnVdQrhDMTHxdEckRGX01XvwXDHUT9zYZ3k0=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0/go.mod h1:+6sju8gk8FRmSajX3Oz4G5Gm7P+mbqE9FVaXXFYTkCM=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 h1:jp0dGvZ7ZK0mgqnTSClMxa5xuRL7NZgHameVYF6BurY=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2 h1:+5VZ72z0Qan5Bog5C+ZkgSqUbeVUd9wgtHOrIKuc5b8=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s=
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0 h1:WVsrXCnHlDDX8ls+tootqRE87/hL9S/g4ewig9RsD/c=
Expand Down
4 changes: 2 additions & 2 deletions sdk/resourcemanager/internal/testutil/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func GetEnv(key, fallback string) string {
// a delegate function to delete the created resource group which can be used for clean up
// and any error during the creation.
func CreateResourceGroup(ctx context.Context, subscriptionId string, cred azcore.TokenCredential, options *arm.ClientOptions, location string) (*armresources.ResourceGroup, func() (*runtime.Poller[armresources.ResourceGroupsClientDeleteResponse], error), error) {
rand.Seed(time.Now().UnixNano())
resourceGroupName := fmt.Sprintf("go-sdk-test-%d", rand.Intn(1000))
r := rand.New(rand.NewSource(time.Now().UnixNano()))
resourceGroupName := fmt.Sprintf("go-sdk-test-%d", r.Intn(1000))
rgClient, err := armresources.NewResourceGroupsClient(subscriptionId, cred, options)
if err != nil {
return nil, nil, err
Expand Down
93 changes: 72 additions & 21 deletions sdk/resourcemanager/internal/testutil/recording.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math/rand"
"net/http"
"strconv"
"strings"
"testing"
"time"

Expand All @@ -21,8 +22,24 @@ import (
const recordingRandomSeedVariableName = "recordingRandomSeed"

var (
recordingRandomSeed int64
letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
recordingSeed int64
recordingRandomSource rand.Source
)

const (
alphanumericBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
alphanumericLowercaseBytes = "abcdefghijklmnopqrstuvwxyz1234567890"
randomSeedVariableName = "randomSeed"
nowVariableName = "now"
ModeEnvironmentVariableName = "AZURE_TEST_MODE"
recordingAssetConfigName = "assets.json"
)

// Inspired by https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
const (
letterIdxBits = 6 // 6 bits to represent a letter index
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
)

type recordingPolicy struct {
Expand Down Expand Up @@ -107,37 +124,71 @@ func StartRecording(t *testing.T, pathToPackage string) func() {

// StopRecording stops the recording.
func StopRecording(t *testing.T) {
err := recording.Stop(t, &recording.RecordingOptions{Variables: map[string]interface{}{recordingRandomSeedVariableName: strconv.FormatInt(recordingRandomSeed, 10)}})
err := recording.Stop(t, &recording.RecordingOptions{Variables: map[string]interface{}{recordingRandomSeedVariableName: strconv.FormatInt(recordingSeed, 10)}})
if err != nil {
t.Fatalf("Failed to stop recording: %v", err)
}
}

func initRandomSource(t *testing.T) {

if recordingRandomSource != nil {
return
}

var seed int64
var err error

variables := recording.GetVariables(t)
seedString, ok := variables[recordingRandomSeedVariableName]
if ok {
seed, err = strconv.ParseInt(seedString.(string), 10, 64)
}

// We did not have a random seed already stored; create a new one
if !ok || err != nil || recording.GetRecordMode() == "live" {
seed = time.Now().Unix()
val := strconv.FormatInt(seed, 10)
variables[recordingRandomSeedVariableName] = &val
}

// create a Source with the seed
recordingRandomSource = rand.NewSource(seed)
recordingSeed = seed
}

// GenerateAlphaNumericID will generate a random alpha numeric ID.
// When handling live request, the random seed is generated.
// Otherwise, the random seed is stable and will be stored in recording file.
// The length parameter is the random part length, not include the prefix part.
func GenerateAlphaNumericID(t *testing.T, prefix string, length int) string {
if recording.GetRecordMode() != "live" {
if recordingRandomSeed == 0 {
variables := recording.GetVariables(t)
if seed, ok := variables[recordingRandomSeedVariableName]; ok {
seedNum, err := strconv.ParseInt(seed.(string), 10, 64)
if err == nil {
recordingRandomSeed = seedNum
}

var lowercaseOnly bool = false
Comment thread
RickWinter marked this conversation as resolved.

initRandomSource(t)
sb := strings.Builder{}
sb.Grow(length)
sb.WriteString(prefix)
i := length - 1
// A src.Int63() generates 63 random bits, enough for letterIdxMax characters!
for cache, remain := recordingRandomSource.Int63(), letterIdxMax; i >= 0; {
if remain == 0 {
cache, remain = recordingRandomSource.Int63(), letterIdxMax
}
if lowercaseOnly {
if idx := int(cache & letterIdxMask); idx < len(alphanumericLowercaseBytes) {
sb.WriteByte(alphanumericLowercaseBytes[idx])
i--
}
if recordingRandomSeed == 0 {
recordingRandomSeed = time.Now().Unix()
} else {
if idx := int(cache & letterIdxMask); idx < len(alphanumericBytes) {
sb.WriteByte(alphanumericBytes[idx])
i--
}
}
rand.Seed(recordingRandomSeed)
} else {
rand.Seed(time.Now().Unix())
}
b := make([]rune, length)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
cache >>= letterIdxBits
remain--
}
return prefix + string(b)
str := sb.String()
return str
}
6 changes: 3 additions & 3 deletions sdk/resourcemanager/internal/testutil/recording_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestRecordingPolicy(t *testing.T) {
require.NoError(t, err)
resp, err := pl.Do(req)
require.NoError(t, err)
require.Equal(t, resp.StatusCode, http.StatusBadRequest)
require.Equal(t, resp.Request.URL.String(), testEndpoint)
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
require.Equal(t, testEndpoint, resp.Request.URL.String())
}

func TestStartStopRecording(t *testing.T) {
Expand All @@ -39,6 +39,6 @@ func TestStartStopRecording(t *testing.T) {
func TestGenerateAlphaNumericID(t *testing.T) {
stop := StartRecording(t, pathToPackage)
rnd := GenerateAlphaNumericID(t, "test", 6)
require.Equal(t, rnd, "testsUJVGl")
require.Equal(t, "testNlDAa8", rnd)
defer stop()
}