Skip to content

Commit

Permalink
Add SetEnvironment method to azure package (#517)
Browse files Browse the repository at this point in the history
Allows modification of the global environments map.
  • Loading branch information
jhendrixMSFT authored May 5, 2020
1 parent e727cfc commit 9132adf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## v14.1.0

### New Features

- Added `azure.SetEnvironment()` that will update the global environments map with the specified values.

## v14.0.1

### Bug Fixes
Expand Down
5 changes: 5 additions & 0 deletions autorest/azure/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,8 @@ func EnvironmentFromFile(location string) (unmarshaled Environment, err error) {

return
}

// SetEnvironment updates the environment map with the specified values.
func SetEnvironment(name string, env Environment) {
environments[strings.ToUpper(name)] = env
}
16 changes: 16 additions & 0 deletions autorest/azure/environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,19 @@ func TestRoundTripSerialization(t *testing.T) {
t.Errorf("Expected ResourceIdentifiers.OperationalInsights to be %q, but got %q", env.ResourceIdentifiers.OperationalInsights, testSubject.ResourceIdentifiers.OperationalInsights)
}
}

func TestSetEnvironment(t *testing.T) {
const testEnvName = "testenvironment"
if _, err := EnvironmentFromName(testEnvName); err == nil {
t.Fatal("expected non-nil error")
}
testEnv := Environment{Name: testEnvName}
SetEnvironment(testEnvName, testEnv)
result, err := EnvironmentFromName(testEnvName)
if err != nil {
t.Fatalf("failed to get custom environment: %v", err)
}
if testEnv != result {
t.Fatalf("expected %v, got %v", testEnv, result)
}
}
2 changes: 1 addition & 1 deletion autorest/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"runtime"
)

const number = "v14.0.1"
const number = "v14.1.0"

var (
userAgent = fmt.Sprintf("Go/%s (%s-%s) go-autorest/%s",
Expand Down

0 comments on commit 9132adf

Please sign in to comment.