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

Add support for replace-existing-checks parameter #155

Merged
merged 2 commits into from
Jul 12, 2022

Conversation

alhimik45
Copy link
Contributor

Consul docs about parameter: https://www.consul.io/api-docs/agent/service#replace-existing-checks
It was added in Consul v1.6.1, but not presented in this library

Copy link
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alhimik45 Thanks for your contribution, your changes look good. I would just improve tests by replacing these two new test methods with single parametrised one:

        [Theory]
        [InlineData(false)]
        [InlineData(true)]
        public async Task Agent_ReRegister_ReplaceExistingChecks(bool replaceExistingChecks)
        {
            var svcID = KVTest.GenerateTestKeyName();
            var check1Name = svcID + "1";
            var check2Name = svcID + "2";
            var check3Name = svcID + "3";
            var registration1 = new AgentServiceRegistration
            {
                Name = svcID,
                Port = 8000,
                Checks = new[]
                {
                    new AgentServiceCheck
                    {
                        Name = check1Name,
                        TTL = TimeSpan.FromSeconds(15)
                    },
                    new AgentServiceCheck
                    {
                        Name = check2Name,
                        TTL = TimeSpan.FromSeconds(15)
                    }
                }
            };
            var registration2 = new AgentServiceRegistration
            {
                Name = svcID,
                Port = 8000,
                Check = new AgentServiceCheck
                {
                    Name = check3Name,
                    TTL = TimeSpan.FromSeconds(15)
                }
            };

            await _client.Agent.ServiceRegister(registration1);
            await _client.Agent.ServiceRegister(registration2, replaceExistingChecks: replaceExistingChecks);

            var checks = await _client.Agent.Checks();

            if (replaceExistingChecks)
            {
                Assert.DoesNotContain(check1Name, checks.Response.Values.Select(c => c.Name));
                Assert.DoesNotContain(check2Name, checks.Response.Values.Select(c => c.Name));
            }
            else
            {
                Assert.Contains(check1Name, checks.Response.Values.Select(c => c.Name));
                Assert.Contains(check2Name, checks.Response.Values.Select(c => c.Name));
            }

            Assert.Contains(check3Name, checks.Response.Values.Select(c => c.Name));

            await _client.Agent.ServiceDeregister(svcID);
        }

Copy link
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@marcin-krystianc marcin-krystianc merged commit 37b907c into G-Research:master Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants