-
Notifications
You must be signed in to change notification settings - Fork 94
feat: introduce Namespace
#229
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
Merged
Merged
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0b041c0
feat: introduce `Namespace`
winstxnhdw 4cc0f50
Merge branch 'master' into namespace
winstxnhdw 1447adc
chore: add notice for enterprise-only features
winstxnhdw 85d3d03
Merge branch 'master' into namespace
marcin-krystianc 9bf414e
Merge branch 'master' into namespace
winstxnhdw 351b98d
feat: add `Namespace` controller
winstxnhdw 2f8186f
Merge branch 'master' into namespace
winstxnhdw 0c32831
fix: intialise `Namespace` correctly
winstxnhdw 79ec6a4
fix: use correct env variable for default namespace
winstxnhdw 9bf6e5b
feat: add overload to use default Query/WriteOptions
winstxnhdw 103cf5b
feat: add test for Namespaces API
winstxnhdw acc987f
chore: remove unused `using`
winstxnhdw cd4fbb7
fix: assign `_namespaces`
winstxnhdw 0cf301e
fix: skip namespace test if not supported
winstxnhdw b0d882d
fix: remove `Partition` field
winstxnhdw b8f4d30
chore: sort usings
winstxnhdw 9e18df6
Merge branch 'master' into namespace
winstxnhdw 207d2a6
fix: use `DateTime` instead of `TimeSpan`
winstxnhdw a32d82b
fix: deleted namespaces are not immediately deleted
winstxnhdw 6274a47
fix: `ToHashSet` is not supported in net461
winstxnhdw b2e85a7
fix: `Put` request must specify incoming response
winstxnhdw 2231c57
refactor: `DeletedAt` should be in main `Namespace` class
winstxnhdw d6931cd
fix: use `EnterpriseOnlyFact` attribute instead
winstxnhdw 3a689cb
refactor: expose correct response
winstxnhdw 6a66429
chore: try skipping without a skippable attribute
winstxnhdw a0812b1
feat: make `EnterpriseOnlyFact` skippable
winstxnhdw b783ee9
chore: fix name when skipping test
winstxnhdw 476dadf
docs: add documentation for Namespaces
winstxnhdw 9064700
refactor: verify if created namespaces exist
winstxnhdw 0c47061
feat: add Namespace test with KV
winstxnhdw f50a2ac
chore: fix comment indentation
winstxnhdw 6f0f8a1
fix: apply dotnet format
winstxnhdw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="NamespaceTest.cs" company="G-Research Limited"> | ||
| // Copyright 2020 G-Research Limited | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using NuGet.Versioning; | ||
| using Xunit; | ||
|
|
||
| namespace Consul.Test | ||
| { | ||
| public class NamespaceTest : BaseFixture | ||
| { | ||
| [EnterpriseOnlyFact] | ||
| public async Task Namespaces_CreateNamespace() | ||
| { | ||
| var cutOffVersion = SemanticVersion.Parse("1.7.0"); | ||
| Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Namespaces` is only supported from Consul {cutOffVersion}"); | ||
|
|
||
| var name = "test"; | ||
|
|
||
| var ns = new Namespace | ||
| { | ||
| Name = name | ||
| }; | ||
|
|
||
| var request = await _client.Namespaces.Create(ns); | ||
|
|
||
| Assert.Equal(request.Response.Name, name); | ||
| } | ||
|
|
||
| [EnterpriseOnlyFact] | ||
| public async Task Namespaces_UpdateNamespace() | ||
| { | ||
| var cutOffVersion = SemanticVersion.Parse("1.7.0"); | ||
| Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Namespaces` is only supported from Consul {cutOffVersion}"); | ||
|
|
||
| var name = "test"; | ||
|
|
||
| var ns = new Namespace | ||
| { | ||
| Name = name | ||
| }; | ||
|
|
||
| await _client.Namespaces.Create(ns); | ||
|
|
||
| var description = "updated namespace"; | ||
|
|
||
| var newNamespace = new Namespace | ||
| { | ||
| Name = name, | ||
| Description = description | ||
| }; | ||
|
|
||
| var updateRequest = await _client.Namespaces.Update(newNamespace); | ||
|
|
||
| Assert.Equal(updateRequest.Response.Description, description); | ||
| } | ||
|
|
||
| [EnterpriseOnlyFact] | ||
| public async Task Namespaces_ReadNamespace() | ||
| { | ||
| var cutOffVersion = SemanticVersion.Parse("1.7.0"); | ||
| Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Namespaces` is only supported from Consul {cutOffVersion}"); | ||
|
|
||
| var name = "test"; | ||
|
|
||
| var ns = new Namespace | ||
| { | ||
| Name = name | ||
| }; | ||
|
|
||
| await _client.Namespaces.Create(ns); | ||
| var request = await _client.Namespaces.Read(name); | ||
|
|
||
| Assert.Equal(request.Response.Name, name); | ||
| } | ||
|
|
||
|
|
||
| [EnterpriseOnlyFact] | ||
| public async Task Namespaces_ListNamespaces() | ||
| { | ||
| var cutOffVersion = SemanticVersion.Parse("1.7.0"); | ||
| Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Namespaces` is only supported from Consul {cutOffVersion}"); | ||
|
|
||
| var testNames = new HashSet<string> { "test-a", "test-b", "test-c" }; | ||
|
|
||
| foreach (var name in testNames) | ||
| { | ||
| var ns = new Namespace | ||
| { | ||
| Name = name | ||
| }; | ||
|
|
||
| await _client.Namespaces.Create(ns); | ||
| } | ||
|
|
||
| var request = await _client.Namespaces.List(); | ||
| testNames.Add("default"); | ||
| Assert.True(new HashSet<string>(request.Response.Select(x => x.Name)).SetEquals(testNames)); | ||
| } | ||
|
|
||
| [EnterpriseOnlyFact] | ||
| public async Task Namespaces_DeleteNamespace() | ||
| { | ||
| var cutOffVersion = SemanticVersion.Parse("1.7.0"); | ||
| Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Namespaces` is only supported from Consul {cutOffVersion}"); | ||
|
|
||
| var name = "test"; | ||
|
|
||
| var ns = new Namespace | ||
| { | ||
| Name = name | ||
| }; | ||
|
|
||
| var createRequest = await _client.Namespaces.Create(ns); | ||
| Assert.Equal(name, createRequest.Response.Name); | ||
| Assert.Null(createRequest.Response.DeletedAt); | ||
|
|
||
| await _client.Namespaces.Delete(name); | ||
|
|
||
| var readRequest = await _client.Namespaces.Read(name); | ||
| Assert.NotNull(readRequest.Response.DeletedAt); | ||
| } | ||
|
|
||
| [EnterpriseOnlyFact] | ||
| public async Task Namespaces_KVIsolation() | ||
| { | ||
| var cutOffVersion = SemanticVersion.Parse("1.7.0"); | ||
| Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Namespaces` is only supported from Consul {cutOffVersion}"); | ||
|
|
||
| var name = "test"; | ||
|
|
||
| await _client.Namespaces.Create(new Namespace | ||
| { | ||
| Name = name | ||
| }); | ||
|
|
||
| var key = "key"; | ||
|
|
||
| var requestPair = new KVPair | ||
| { | ||
| Key = key, | ||
| Value = Encoding.UTF8.GetBytes("value") | ||
| }; | ||
|
|
||
| await _client.KV.Put(requestPair, new WriteOptions { Namespace = name }); | ||
| var namespaceResponsePair = await _client.KV.Get(key, new QueryOptions { Namespace = name }); | ||
| Assert.Equal(requestPair.Value, namespaceResponsePair.Response.Value); | ||
|
|
||
| var defaultNamespaceResponsePair = await _client.KV.Get(key); | ||
| Assert.Null(defaultNamespaceResponsePair.Response?.Value); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.