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

fix: write correct value for KV.Release #237

Merged
merged 9 commits into from
Sep 6, 2023
16 changes: 9 additions & 7 deletions Consul.Test/KVTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public async Task KV_Keys_DeleteRecurse()
Assert.Equal(pairs.Response.Length, putTasks.Length);
Assert.False(pairs.LastIndex == 0);

var deleteTree = await _client.KV.DeleteTree(prefix);
await _client.KV.DeleteTree(prefix);

pairs = await _client.KV.Keys(prefix, "");
Assert.Null(pairs.Response);
Expand All @@ -363,12 +363,12 @@ public async Task KV_AcquireRelease()
Assert.False(string.IsNullOrEmpty(sessionRequest.Response));

var key = GenerateTestKeyName();
var value = Encoding.UTF8.GetBytes("test");
var value = "test";

var pair = new KVPair(key)
{
Value = value,
Session = id
Value = Encoding.UTF8.GetBytes(value),
Session = id,
};

var acquireRequest = await _client.KV.Acquire(pair);
Expand All @@ -381,12 +381,14 @@ public async Task KV_AcquireRelease()
Assert.Equal(getRequest.Response.LockIndex, (ulong)1);
Assert.True(getRequest.LastIndex > 0);

acquireRequest = await _client.KV.Release(pair);
Assert.True(acquireRequest.Response);
var newValue = "test2";
pair.Value = Encoding.UTF8.GetBytes(newValue);
var releaseRequest = await _client.KV.Release(pair);
Assert.True(releaseRequest.Response);

getRequest = await _client.KV.Get(key);

Assert.NotNull(getRequest.Response);
Assert.Equal(newValue, Encoding.UTF8.GetString(getRequest.Response.Value));
Assert.Null(getRequest.Response.Session);
Assert.Equal(getRequest.Response.LockIndex, (ulong)1);
Assert.True(getRequest.LastIndex > 0);
Expand Down
8 changes: 2 additions & 6 deletions Consul/KV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
Expand Down Expand Up @@ -509,7 +508,7 @@ public Task<WriteResult<bool>> Release(KVPair p, CancellationToken ct = default)
public Task<WriteResult<bool>> Release(KVPair p, WriteOptions q, CancellationToken ct = default)
{
p.Validate();
var req = _client.Put<object, bool>(string.Format("/v1/kv/{0}", p.Key.TrimStart('/')), null, q);
var req = _client.Put<byte[], bool>(string.Format("/v1/kv/{0}", p.Key.TrimStart('/')), p.Value, q);
if (p.Flags > 0)
{
req.Params["flags"] = p.Flags.ToString();
Expand Down Expand Up @@ -620,9 +619,6 @@ public partial class ConsulClient : IConsulClient
/// <summary>
/// KV returns a handle to the KV endpoint
/// </summary>
public IKVEndpoint KV
{
get { return _kv.Value; }
}
public IKVEndpoint KV => _kv.Value;
}
}