Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct New-CosmosDbContext Environment output - Fixes #411 #416

Merged
merged 1 commit into from
May 22, 2021
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Convert build pipeline to use GitTools Azure DevOps extension tasks
instead of deprecated GitVersion extension.
- Correct value of `Environment` parameter in context object returned
by `New-CosmosDbContext` - Fixes [Issue #411](https://github.com/PlagueHO/CosmosDB/issues/411).

### Fixed

Expand Down
1 change: 1 addition & 0 deletions source/Public/utils/New-CosmosDbContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ function New-CosmosDbContext
BaseUri = $BaseUri
Token = $Token
BackoffPolicy = $BackoffPolicy
Environment = $Environment
}

return $context
Expand Down
2 changes: 1 addition & 1 deletion source/classes/CosmosDB/CosmosDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Context
public System.String BaseUri;
public CosmosDB.ContextToken[] Token;
public CosmosDB.BackoffPolicy BackoffPolicy;
public CosmosDB.Environment Environment;
public CosmosDB.Environment Environment = Environment.AzureCloud;
}

namespace IndexingPolicy {
Expand Down
21 changes: 19 additions & 2 deletions tests/Unit/CosmosDB.utils.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ console.log("done");
$script:result.Key | Should -Be $script:testKeySecureString
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureCloud)
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -258,6 +259,7 @@ console.log("done");
$script:result.Key | Should -Be $script:testKeySecureString
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureUsGov)
$script:result.Environment | Should -BeExactly 'AzureUSGovernment'
}
}

Expand All @@ -282,6 +284,7 @@ console.log("done");
$script:result.Key | Should -Be $script:testKeySecureString
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureChinaCloud)
$script:result.Environment | Should -BeExactly 'AzureChinaCloud'
}
}

Expand All @@ -306,6 +309,7 @@ console.log("done");
$script:result.Key | Should -Be $script:testKeySecureString
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureCustomEndpoint)
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand Down Expand Up @@ -341,6 +345,7 @@ console.log("done");
$script:result.BackoffPolicy.MaxRetries | Should -Be $script:testMaxRetries
$script:result.BackoffPolicy.Method | Should -Be $script:testMethod
$script:result.BackoffPolicy.Delay | Should -Be $script:testDelay
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand Down Expand Up @@ -370,6 +375,7 @@ console.log("done");
$script:result.KeyType | Should -Be 'master'
$script:result.Key | Convert-CosmosDbSecureStringToString | Should -Be $script:testKey
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureCloud)
$script:result.Environment | Should -BeExactly 'AzureCloud'
}

It 'Should call expected mocks' {
Expand Down Expand Up @@ -437,6 +443,7 @@ console.log("done");
$script:result.KeyType | Should -Be 'master'
$script:result.Key | Convert-CosmosDbSecureStringToString | Should -Be $script:testKey
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureUsGov)
$script:result.Environment | Should -BeExactly 'AzureUSGovernment'
}

It 'Should call expected mocks' {
Expand Down Expand Up @@ -477,6 +484,7 @@ console.log("done");
$script:result.KeyType | Should -Be 'master'
$script:result.Key | Convert-CosmosDbSecureStringToString | Should -Be $script:testKey
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureChinaCloud)
$script:result.Environment | Should -BeExactly 'AzureChinaCloud'
}

It 'Should call expected mocks' {
Expand Down Expand Up @@ -515,6 +523,7 @@ console.log("done");
$script:result.KeyType | Should -Be 'master'
$script:result.Key | Convert-CosmosDbSecureStringToString | Should -Be $script:testKey
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureCloud)
$script:result.Environment | Should -BeExactly 'AzureCloud'
}

It 'Should call expected mocks' {
Expand Down Expand Up @@ -552,6 +561,7 @@ console.log("done");
$script:result.KeyType | Should -Be 'master'
$script:result.Key | Convert-CosmosDbSecureStringToString | Should -Be $script:testKey
$script:result.BaseUri | Should -Be ('https://{0}.{1}/' -f $script:testAccount, $script:testBaseHostnameAzureCustomEndpoint)
$script:result.Environment | Should -BeExactly 'AzureCloud'
}

It 'Should call expected mocks' {
Expand Down Expand Up @@ -583,6 +593,7 @@ console.log("done");
$tempCredential.Password | Should -Be $script:testEmulatorKey
$script:result.KeyType | Should -BeExactly 'master'
$script:result.BaseUri | Should -BeExactly 'https://localhost:8081/'
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -608,6 +619,7 @@ console.log("done");
$tempCredential.Password | Should -Be $script:testEmulatorKey
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be 'https://mycosmosdb.contoso.local:9999/'
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -632,6 +644,7 @@ console.log("done");
$tempCredential.Password | Should -Be $script:testEmulatorKey
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be 'https://mycosmosdb.contoso.local:8081/'
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -656,6 +669,7 @@ console.log("done");
$tempCredential.Password | Should -Be $script:testEmulatorKey
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be 'http://mycosmosdb.contoso.local:8081/'
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -680,6 +694,7 @@ console.log("done");
$tempCredential.Password | Should -Be $script:testEmulatorKey
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be 'https://mycosmosdb.contoso.local:9999/'
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -704,6 +719,7 @@ console.log("done");
$tempCredential.Password | Should -Be $script:testEmulatorKey
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be 'https://mycosmosdb.contoso.local:9999/'
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -729,6 +745,7 @@ console.log("done");
$tempCredential.Password | Should -Be $script:testEmulatorKey
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be 'https://mycosmosdb.contoso.local:8081/'
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -754,6 +771,7 @@ console.log("done");
$tempCredential.Password | Should -Be $script:testKey
$script:result.KeyType | Should -Be 'master'
$script:result.BaseUri | Should -Be 'https://localhost:8081/'
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}

Expand All @@ -778,10 +796,9 @@ console.log("done");
$script:result.Token[0].Resource | Should -Be $script:testTokenResource
$script:result.Token[0].TimeStamp | Should -Be $script:testDate
$script:result.Token[0].Token | Convert-CosmosDbSecureStringToString | Should -Be $script:testToken
$script:result.Environment | Should -BeExactly 'AzureCloud'
}
}


}

Describe 'Get-CosmosDbUri' -Tag 'Unit' {
Expand Down