public async Task agent_Service() { using (var client = new ConsulRsetApiClient()) { var registration = new ConsulAgentServiceRegistration() { Name = "foo", Tags = new[] { "bar", "baz" }, Port = 8000, Check = new ConsulAgentServiceCheck { TTL = "15s" } }; await client.agentServiceRegisterAsync(registration).ConfigureAwait(false); var services = await client.agentServicesAsync().ConfigureAwait(false); Assert.True(services.ResponseData.ContainsKey("foo")); var checks = await client.agentChecksAsync().ConfigureAwait(false); Assert.True(checks.ResponseData.ContainsKey("service:foo")); Assert.Equal("critical", checks.ResponseData["service:foo"].Status); await client.agentServiceDeregisterAsync("foo").ConfigureAwait(false); services = await client.agentServicesAsync().ConfigureAwait(false); Assert.False(services.ResponseData.ContainsKey("foo")); } }
public async Task kv_Keys_Get_Delete() { using (var client = new ConsulRsetApiClient()) { var prefix = GenerateTestKeyName(); for (var i = 0; i < 100; i++) { var key = string.Join("/", prefix, GenerateTestKeyName()); Assert.True((await client.kvPutAsync(key, "test").ConfigureAwait(false)).ResponseData); } var keysResponse = await client.kvGetKeysAsync(prefix).ConfigureAwait(false); Assert.NotNull(keysResponse.ResponseData); Assert.Equal(keysResponse.ResponseData.Length, 100); var deleteResponse = await client.kvDeleteListAsync(prefix).ConfigureAwait(false); Assert.True(deleteResponse.ResponseData); keysResponse = await client.kvGetKeysAsync(prefix).ConfigureAwait(false); Assert.Null(keysResponse.ResponseData); } }
public async Task kv_Put_Get_Delete() { using (var client = new ConsulRsetApiClient()) { var key = GenerateTestKeyName(); var getResponse = await client.kvGetAsync(key).ConfigureAwait(false); Assert.Null(getResponse.ResponseData); var putResponse = await client.kvPutAsync(key, "test", true).ConfigureAwait(false); Assert.True(putResponse.ResponseData); getResponse = await client.kvGetAsync(key).ConfigureAwait(false); Assert.NotNull(getResponse.ResponseData); var getRawResponse = await client.kvGetRawAsync(key).ConfigureAwait(false); Assert.True(string.Compare("test", getRawResponse.ResponseData, true) == 0); var deleteResponse = await client.kvDeleteAsync(key).ConfigureAwait(false); Assert.True(deleteResponse.ResponseData); getResponse = await client.kvGetAsync(key).ConfigureAwait(false); Assert.Null(getResponse.ResponseData); } }
public async Task kv_List_Get_Delete() { using (var client = new ConsulRsetApiClient()) { var prefix = GenerateTestKeyName(); for (var i = 0; i < 100; i++) { var key = string.Join("/", prefix, GenerateTestKeyName()); Assert.True((await client.kvPutAsync(key, "test").ConfigureAwait(false)).ResponseData); } var listResponse = await client.kvGetListAsync(prefix).ConfigureAwait(false); Assert.NotNull(listResponse.ResponseData); Assert.Equal(listResponse.ResponseData.Length, 100); var encodeValue = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")); foreach (var pair in listResponse.ResponseData) { Assert.True(string.Compare(encodeValue, pair.Value, true) == 0); } var deleteResponse = await client.kvDeleteListAsync(prefix).ConfigureAwait(false); Assert.True(deleteResponse.ResponseData); listResponse = await client.kvGetListAsync(prefix).ConfigureAwait(false); Assert.Null(listResponse.ResponseData); } }
public async Task health_Service() { using (var client = new ConsulRsetApiClient()) { var checks = await client.healthServiceAsync("consul", "", true).ConfigureAwait(false); Assert.NotEqual(0, checks.ResponseData.Length); } }