-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl.sh
executable file
·75 lines (67 loc) · 1.63 KB
/
curl.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
url='http://localhost:6026/key/test/key'
if [ "$1" = "docker" ]
then
url='http://localhost:6020/key/test/key'
fi
lurl='http://localhost:6026/list/test'
if [ "$1" = "docker" ]
then
lurl='http://localhost:6020/list/test'
fi
Put()
{
echo "PUT request for key test"
value=`curl -s -k --http2-prior-knowledge -XPUT -H "content-type: text/plain" -d "value" $url | jq -r .code`
if [ "$value" = "200" ]
then
echo "Saved key-value pair"
else
echo "Error saving key-value pair"
fi
}
PutNotExists()
{
echo "PUT request for key test with if_not_exists"
value=`curl -s -k --http2-prior-knowledge -XPUT -H "content-type: text/plain" -H "x-config-db-if-not-exists: true" -d "value" $url | jq -r .code`
if [ "$value" = "412" ]
then
echo "Updating existing key-value pair rejected due to header"
else
echo "Error. Updated key-value pair"
fi
}
Get()
{
echo "GET request for key test"
value=`curl -s -k --http2-prior-knowledge $url | jq -r .value`
if [ "$value" = "value" ]
then
echo "Expected value retrieved"
else
echo "Unexpected value [$value] received"
fi
}
List()
{
echo "GET request for listing child nodes"
value=`curl -s -k --http2-prior-knowledge $lurl | jq -r .children[0]`
if [ "$value" = "key" ]
then
echo "Expected value retrieved"
else
echo "Unexpected value ($value) received"
fi
}
Delete()
{
echo "DELETE request for key test"
value=`curl -s -k --http2-prior-knowledge -XDELETE $url | jq -r .code`
if [ "$value" = "200" ]
then
echo "Deleted key-value pair"
else
echo "Error deleting key-value pair"
fi
}
Put && Get && List && PutNotExists && Delete