|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Docker.DotNet.Models; |
| 4 | +using Xunit; |
| 5 | +using Xunit.Abstractions; |
| 6 | + |
| 7 | +namespace Docker.DotNet.Tests |
| 8 | +{ |
| 9 | + [Collection(nameof(TestCollection))] |
| 10 | + public class IConfigOperationsTests |
| 11 | + { |
| 12 | + private readonly DockerClientConfiguration _dockerClientConfiguration; |
| 13 | + private readonly DockerClient _dockerClient; |
| 14 | + private readonly TestOutput _output; |
| 15 | + public IConfigOperationsTests(TestFixture testFixture, ITestOutputHelper outputHelper) |
| 16 | + { |
| 17 | + _dockerClientConfiguration = testFixture.DockerClientConfiguration; |
| 18 | + _dockerClient = _dockerClientConfiguration.CreateClient(); |
| 19 | + _output = new TestOutput(outputHelper); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public async void SwarmConfig_CanCreateAndRead() |
| 24 | + { |
| 25 | + var currentConfigs = await _dockerClient.Configs.ListConfigsAsync(); |
| 26 | + |
| 27 | + _output.WriteLine($"Current Configs: {currentConfigs.Count}"); |
| 28 | + |
| 29 | + var testConfigSpec = new SwarmConfigSpec |
| 30 | + { |
| 31 | + Name = $"Config-{Guid.NewGuid().ToString().Substring(1, 10)}", |
| 32 | + Labels = new Dictionary<string, string> { { "key", "value" } }, |
| 33 | + Data = new List<byte> { 1, 2, 3, 4, 5 } |
| 34 | + }; |
| 35 | + |
| 36 | + var configParameters = new SwarmCreateConfigParameters |
| 37 | + { |
| 38 | + Config = testConfigSpec |
| 39 | + }; |
| 40 | + |
| 41 | + var createdConfig = await _dockerClient.Configs.CreateConfigAsync(configParameters); |
| 42 | + Assert.NotNull(createdConfig.ID); |
| 43 | + _output.WriteLine($"Config created: {createdConfig.ID}"); |
| 44 | + |
| 45 | + var configs = await _dockerClient.Configs.ListConfigsAsync(); |
| 46 | + Assert.Contains(configs, c => c.ID == createdConfig.ID); |
| 47 | + _output.WriteLine($"Current Configs: {configs.Count}"); |
| 48 | + |
| 49 | + var configResponse = await _dockerClient.Configs.InspectConfigAsync(createdConfig.ID); |
| 50 | + |
| 51 | + Assert.NotNull(configResponse); |
| 52 | + |
| 53 | + Assert.Equal(configResponse.Spec.Name, testConfigSpec.Name); |
| 54 | + Assert.Equal(configResponse.Spec.Data, testConfigSpec.Data); |
| 55 | + Assert.Equal(configResponse.Spec.Labels, testConfigSpec.Labels); |
| 56 | + Assert.Equal(configResponse.Spec.Templating, testConfigSpec.Templating); |
| 57 | + |
| 58 | + |
| 59 | + _output.WriteLine($"Config created is the same."); |
| 60 | + |
| 61 | + await _dockerClient.Configs.RemoveConfigAsync(createdConfig.ID); |
| 62 | + |
| 63 | + await Assert.ThrowsAsync<Docker.DotNet.DockerApiException>(() => _dockerClient.Configs.InspectConfigAsync(createdConfig.ID)); |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
0 commit comments