コード例 #1
0
        public async Task AddAnnotations_will_not_override_annotations()
        {
            // Arrange
            var namespaceName =
                NamespaceName.Create("namespace-from-test-" + Guid.NewGuid().ToString().Substring(0, 5));


            var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
            var client = new k8s.Kubernetes(config);

            var sut = new NamespaceRepository(client);

            try
            {
                await sut.CreateNamespaceAsync(namespaceName);

                var annotationsRoundOne = new Dictionary <string, string>
                {
                    { "type-a", "ab" },
                    { "type-b", "bc" }
                };

                await sut.AddAnnotations(namespaceName, annotationsRoundOne);

                var annotationsRoundTwo = new Dictionary <string, string>
                {
                    { "type-a", "not ab" }
                };

                // Act / Assert
                Assert.ThrowsAsync <Exception>(async() => await sut.AddAnnotations(namespaceName, annotationsRoundTwo));
            }
            finally
            {
                client.DeleteNamespace(
                    body: new V1DeleteOptions(),
                    name: namespaceName
                    );
            }
        }
コード例 #2
0
        public async Task AddAnnotations_can_add_annotations_when_none_exits()
        {
            var namespaceName =
                NamespaceName.Create("namespace-from-test-" + Guid.NewGuid().ToString().Substring(0, 5));


            var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
            var client = new k8s.Kubernetes(config);

            var sut = new NamespaceRepository(client);

            try
            {
                await sut.CreateNamespaceAsync(namespaceName);

                var annotations = new Dictionary <string, string>
                {
                    { "type-a", "ab" },
                    { "type-b", "bc" }
                };

                // Act
                await sut.AddAnnotations(namespaceName, annotations);


                // Assert
                var resultNamespace = client.ReadNamespace(namespaceName);

                var resultAnnotations = resultNamespace.Metadata.Annotations;

                Assert.Equal(annotations, resultAnnotations);
            }
            finally
            {
                client.DeleteNamespace(
                    body: new V1DeleteOptions(),
                    name: namespaceName
                    );
            }
        }