Skip to content

Commit 0cf20e3

Browse files
authored
Feature/generics (#17381)
* Update CI to use Go 1.18beta.2 (#16963) * Update CI to use Go 1.18beta.2 * add prerelease install template revert some unneeded changes * fix parameters references * fix curl * use archive names * fix param * update linter * build linters from source, display Go version * lint clean * fix smoke test version detection * Update build constraints to Go 1.18 (#16966) Specify 1.18 in go.mod file. * Disable linter for now (#16975) * Disable linter for now Blows up on generic type parameters so disabling until it's working. Restored installation to its original form. * skip on linter install failure * Convert to package, JSON null funcs to generics (#16973) NullValue now takes a generic type parameter instead of an interface arg to determine the type of null sentinel value to create. IsNullValue infers its generic parameter to determine the type of null sentinel value to look for. At present, there is no way to express a 'nillable' generic type constraint so the funcs simply take a [T any] which should be fine as they typically take/return pointer-to-types. The 'to' package has been reduced to two funcs. * Disable publishing test results for now (#16979) * Disable publishing test results for now It's broken due to lack of generics support. Test failures will still block CI though. * revert fake failure * exclude track 2 from track 1 Format Check CI step * refine track 1 gofmt check * Migrate expiring resource to generics (#16974) * Add generic pager implementation (#17027) * Add generic pager implementation * refine first page flag and processor vars * refine per feedback, start adding tests * fix LRO case, add remaining tests * more consolidation * update changelog * remove page param, use unmarshal instead * Add generic poller implementation (#17297) Due to lack of support for type aliasing a generic type, we have duplicate definitions for ARM and data-plane. We can consolidate the definitions when type aliasing support is added in the future. * Clean-up in prep for merging feature/generics to main (#17380) * Clean-up in prep for merging feature/generics to main Removed some temporary CI changes after rebasing on main. Added missing entries to the changelog. Bumped version to v0.23.0 for breaking changes. * bump golangci-lint to latest version * switch to temporary fork of gocov
1 parent c12bc86 commit 0cf20e3

File tree

99 files changed

+812
-671
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+812
-671
lines changed

azure-pipelines.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ jobs:
105105
failOnStderr: true
106106
condition: succeededOrFailed()
107107

108-
- script: gofmt -s -l -d $(find . -path ./vendor -prune -o -name '*.go' -print) >&2
108+
- script: |
109+
for dd in $(go.list.filter); do
110+
cd $(sdkPath)/$dd
111+
gofmt -s -l -d $(find . -name '*.go' -print) >&2
112+
done
109113
workingDirectory: '$(sdkPath)'
110114
displayName: 'Format Check'
111115
failOnStderr: true

eng/.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
run:
33
# default is true. Enables skipping of directories:
44
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
5-
skip-dirs-use-default: true
5+
skip-dirs-use-default: true

eng/pipelines/templates/jobs/archetype-sdk-client-samples.yml

-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ stages:
2323
pool.name: azsdk-pool-mms-win-2019-general
2424
image.name: MMS2019
2525
go.version: '1.18'
26-
Linux_Go117:
27-
pool.name: azsdk-pool-mms-ubuntu-2004-general
28-
image.name: MMSUbuntu20.04
29-
go.version: '1.17.8'
30-
Windows_Go117:
31-
pool.name: azsdk-pool-mms-win-2019-general
32-
image.name: MMS2019
33-
go.version: '1.17.8'
3426
pool:
3527
name: $(pool.name)
3628
vmImage: $(image.name)

eng/pipelines/templates/jobs/archetype-sdk-client.yml

-8
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ stages:
8888
image.name: MMS2019
8989
go.version: '1.18'
9090
generate.bom: true
91-
Linux_Go117:
92-
pool.name: azsdk-pool-mms-ubuntu-2004-general
93-
image.name: MMSUbuntu20.04
94-
go.version: '1.17.8'
95-
Windows_Go117:
96-
pool.name: azsdk-pool-mms-win-2019-general
97-
image.name: MMS2019
98-
go.version: '1.17.8'
9991
pool:
10092
name: $(pool.name)
10193
vmImage: $(image.name)

eng/pipelines/templates/steps/build-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ steps:
4141

4242
- pwsh: |
4343
go install github.com/jstemmer/go-junit-report@v0.9.1
44-
go install github.com/axw/gocov/gocov@v1.0.0
44+
go install github.com/jhendrixMSFT/gocov/gocov@v1.0.1-0.20220325195445-df8497555dba
4545
go install github.com/AlekSi/gocov-xml@v1.0.0
4646
go install github.com/matm/gocov-html@v0.0.0-20200509184451-71874e2e203b
4747
displayName: "Install Coverage and Junit Dependencies"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
- name: archive
3+
type: string
4+
5+
steps:
6+
- pwsh: |
7+
curl -sSL -o goarchive https://dl.google.com/go/${{parameters.archive}}
8+
tar -xzf goarchive -C "$(Build.SourcesDirectory)/.."
9+
10+
Write-Host "Prepending Path with $(Build.SourcesDirectory)/../go/bin"
11+
12+
# also prepend the path permanently to ensure access the newly installed tools
13+
Write-Host "##vso[task.prependpath]$(Build.SourcesDirectory)/../go/bin"
14+
go version
15+
displayName: "Install Go Pre-release Version"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
variables:
2-
GoLintCLIVersion: 'v1.45.0'
2+
GoLintCLIVersion: 'v1.45.2'
33
Package.EnableSBOMSigning: true

eng/scripts/MgmtTestLib.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function TestAndGenerateReport($dir)
298298
Set-Location $dir
299299
# dependencies for go coverage report generation
300300
go get github.com/jstemmer/go-junit-report
301-
go get github.com/axw/gocov/gocov
301+
go get github.com/jhendrixMSFT/gocov/gocov
302302
go get github.com/AlekSi/gocov-xml
303303
go get github.com/matm/gocov-html
304304

eng/scripts/run_tests.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ go test -timeout $testTimeout -v -coverprofile coverage.txt ./... | Tee-Object -
1212
if ($LASTEXITCODE) {
1313
exit $LASTEXITCODE
1414
}
15+
1516
Get-Content outfile.txt | go-junit-report > report.xml
1617

1718
# if no tests were actually run (e.g. examples) delete the coverage file so it's omitted from the coverage report
@@ -42,4 +43,4 @@ if (Select-String -path ./report.xml -pattern '<testsuites></testsuites>' -simpl
4243
-config $repoRoot/eng/config.json `
4344
-serviceDirectory $serviceDirectory `
4445
-searchDirectory $repoRoot
45-
}
46+
}

eng/tools/smoketests/cmd/root.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ func handle(e error) {
5252
}
5353

5454
func getVersion() string {
55-
v := runtime.Version()
56-
if strings.Contains(v, "go") {
57-
v = strings.TrimLeft(v, "go")
58-
59-
return fmt.Sprintf("go %s", v)
55+
ver := regexp.MustCompile(`\d\.\d{2}`)
56+
if m := ver.FindString(runtime.Version()); m != "" {
57+
return fmt.Sprintf("go %s", m)
6058
}
6159

6260
// Default, go is not from a tag

sdk/azcore/CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Release History
22

3-
## 0.22.1 (Unreleased)
3+
## 0.23.0 (Unreleased)
44

55
### Features Added
6+
* Added `runtime.Pager[T any]` and `runtime.Poller[T any]` supporting types for central, generic, implementations.
67

78
### Breaking Changes
9+
* Removed the `Poller` type-alias to the internal poller implementation.
10+
* Added `Ptr[T any]` and `SliceOfPtrs[T any]` in the `to` package and removed all non-generic implementations.
11+
* `NullValue` and `IsNullValue` now take a generic type parameter instead of an interface func parameter.
812

913
### Bugs Fixed
1014

1115
### Other Changes
16+
* Converted expiring resource and dependent types to use generics.
1217

1318
## 0.22.0 (2022-03-03)
1419

sdk/azcore/arm/client_options.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright 2017 Microsoft Corporation. All rights reserved.
55
// Use of this source code is governed by an MIT

sdk/azcore/arm/example_resource_identifier_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/internal/pollers/async/async.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/internal/pollers/async/async_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/internal/pollers/body/body.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/internal/pollers/body/body_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/internal/pollers/loc/loc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/internal/pollers/loc/loc_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/internal/pollers/pollers.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/internal/pollers/pollers_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/policy/policy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/resource_identifier.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/resource_identifier_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/resource_type.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/resource_type_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/runtime/pipeline.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/runtime/pipeline_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/runtime/policy_bearer_token.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ type acquiringResourceState struct {
2323

2424
// acquire acquires or updates the resource; only one
2525
// thread/goroutine at a time ever calls this function
26-
func acquire(state interface{}) (newResource interface{}, newExpiration time.Time, err error) {
27-
s := state.(acquiringResourceState)
28-
tk, err := s.p.cred.GetToken(s.ctx, shared.TokenRequestOptions{
29-
Scopes: s.p.options.Scopes,
30-
TenantID: s.tenant,
26+
func acquire(state acquiringResourceState) (newResource *shared.AccessToken, newExpiration time.Time, err error) {
27+
tk, err := state.p.cred.GetToken(state.ctx, shared.TokenRequestOptions{
28+
Scopes: state.p.options.Scopes,
29+
TenantID: state.tenant,
3130
})
3231
if err != nil {
3332
return nil, time.Time{}, err
@@ -38,9 +37,9 @@ func acquire(state interface{}) (newResource interface{}, newExpiration time.Tim
3837
// BearerTokenPolicy authorizes requests with bearer tokens acquired from a TokenCredential.
3938
type BearerTokenPolicy struct {
4039
// mainResource is the resource to be retreived using the tenant specified in the credential
41-
mainResource *shared.ExpiringResource
40+
mainResource *shared.ExpiringResource[*shared.AccessToken, acquiringResourceState]
4241
// auxResources are additional resources that are required for cross-tenant applications
43-
auxResources map[string]*shared.ExpiringResource
42+
auxResources map[string]*shared.ExpiringResource[*shared.AccessToken, acquiringResourceState]
4443
// the following fields are read-only
4544
cred shared.TokenCredential
4645
options armpolicy.BearerTokenOptions
@@ -59,7 +58,7 @@ func NewBearerTokenPolicy(cred shared.TokenCredential, opts *armpolicy.BearerTok
5958
mainResource: shared.NewExpiringResource(acquire),
6059
}
6160
if len(opts.AuxiliaryTenants) > 0 {
62-
p.auxResources = map[string]*shared.ExpiringResource{}
61+
p.auxResources = map[string]*shared.ExpiringResource[*shared.AccessToken, acquiringResourceState]{}
6362
}
6463
for _, t := range opts.AuxiliaryTenants {
6564
p.auxResources[t] = shared.NewExpiringResource(acquire)
@@ -78,17 +77,15 @@ func (b *BearerTokenPolicy) Do(req *azpolicy.Request) (*http.Response, error) {
7877
if err != nil {
7978
return nil, err
8079
}
81-
if token, ok := tk.(*shared.AccessToken); ok {
82-
req.Raw().Header.Set(shared.HeaderAuthorization, shared.BearerTokenPrefix+token.Token)
83-
}
80+
req.Raw().Header.Set(shared.HeaderAuthorization, shared.BearerTokenPrefix+tk.Token)
8481
auxTokens := []string{}
8582
for tenant, er := range b.auxResources {
8683
as.tenant = tenant
8784
auxTk, err := er.GetResource(as)
8885
if err != nil {
8986
return nil, err
9087
}
91-
auxTokens = append(auxTokens, fmt.Sprintf("%s%s", shared.BearerTokenPrefix, auxTk.(*shared.AccessToken).Token))
88+
auxTokens = append(auxTokens, fmt.Sprintf("%s%s", shared.BearerTokenPrefix, auxTk.Token))
9289
}
9390
if len(auxTokens) > 0 {
9491
req.Raw().Header.Set(shared.HeaderAuxiliaryAuthorization, strings.Join(auxTokens, ", "))

sdk/azcore/arm/runtime/policy_register_rp.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

sdk/azcore/arm/runtime/policy_register_rp_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.

0 commit comments

Comments
 (0)