aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/curl/curl_test.go
blob: 448e1e5199f19a1a564c64a12f400ce208feab8f (plain) (blame)
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
43
44
45
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package curl

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestPost(t *testing.T) {
	c, err := Post("https://example.com")
	if err != nil {
		t.Fatal(err)
	}
	c.PrivateKey = "key.pem"
	c.Certificate = "cert.pem"
	c.WithBodyFile("file.json")
	c.Header("Content-Type", "application/json")

	assert.Equal(t, "curl --key key.pem --cert cert.pem -X POST -H 'Content-Type: application/json' --data-binary @file.json https://example.com", c.String())
}

func TestGet(t *testing.T) {
	c, err := Get("https://example.com")
	if err != nil {
		t.Fatal(err)
	}
	c.PrivateKey = "key.pem"
	c.Certificate = "cert.pem"
	c.Param("yql", "select * from sources * where title contains 'foo';")
	c.Param("hits", "5")

	assert.Equal(t, `curl --key key.pem --cert cert.pem https://example.com\?hits=5\&yql=select+%2A+from+sources+%2A+where+title+contains+%27foo%27%3B`, c.String())
}

func TestRawArgs(t *testing.T) {
	c, err := RawArgs("https://example.com/search", "-v", "-m", "10", "-H", "foo: bar")
	if err != nil {
		t.Fatal(err)
	}
	c.PrivateKey = "key.pem"
	c.Certificate = "cert.pem"

	assert.Equal(t, `curl --key key.pem --cert cert.pem -v -m 10 -H 'foo: bar' https://example.com/search`, c.String())
}