File: set_curl_chan_test.go

package info (click to toggle)
golang-etcd 0.2.0~rc1%2Bgit20140717-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-backports, jessie-kfreebsd
  • size: 188 kB
  • ctags: 165
  • sloc: makefile: 5
file content (42 lines) | stat: -rw-r--r-- 834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package etcd

import (
	"fmt"
	"testing"
)

func TestSetCurlChan(t *testing.T) {
	c := NewClient(nil)
	c.OpenCURL()

	defer func() {
		c.Delete("foo", true)
	}()

	_, err := c.Set("foo", "bar", 5)
	if err != nil {
		t.Fatal(err)
	}

	expected := fmt.Sprintf("curl -X PUT %s/v2/keys/foo -d value=bar -d ttl=5",
		c.cluster.Leader)
	actual := c.RecvCURL()
	if expected != actual {
		t.Fatalf(`Command "%s" is not equal to expected value "%s"`,
			actual, expected)
	}

	c.SetConsistency(STRONG_CONSISTENCY)
	_, err = c.Get("foo", false, false)
	if err != nil {
		t.Fatal(err)
	}

	expected = fmt.Sprintf("curl -X GET %s/v2/keys/foo?consistent=true&recursive=false&sorted=false",
		c.cluster.Leader)
	actual = c.RecvCURL()
	if expected != actual {
		t.Fatalf(`Command "%s" is not equal to expected value "%s"`,
			actual, expected)
	}
}