pierresouchay / consul-rust

Rust client libray for Consul HTTP API
Apache License 2.0
92 stars 48 forks source link

KV put stores value with quotes #49

Open tomers opened 3 years ago

tomers commented 3 years ago

See https://github.com/pierresouchay/consul-rust/pull/48.

Test code:

let pair = KVPair {
        Key: String::from("testkey"),
        Value: String::from("testvalue"),
        ..Default::default()
    };

    assert!(client.put(&pair, None).unwrap().0);

    let b64val = client.get("testkey", None).unwrap().0.unwrap().Value;
    let bytes = base64::decode(b64val).unwrap();
    assert_eq!(std::str::from_utf8(&bytes).unwrap().to_string(), "testvalue");

Result:

running 1 test
test kv_test ... FAILED

failures:

---- kv_test stdout ----
thread 'kv_test' panicked at 'assertion failed: `(left == right)`
  left: `"\"testvalue\""`,
 right: `"testvalue"`', tests/kv.rs:23:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    kv_test
tomers commented 3 years ago

I think it caused by write_with_body that stores the value as Json:

    let builder = if let Some(b) = body {
        builder.json(b)
    } else {
        builder
    };