Skip to content

Commit

Permalink
Issue-411 - Fixed environment in context (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueHO authored May 22, 2021
1 parent 7ca25c5 commit 8b20ce4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
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

0 comments on commit 8b20ce4

Please sign in to comment.