Refactors unit test code
[icn.git] / cmd / bpa-restapi-agent / e2e_test.sh
1 #!/bin/bash
2
3 ICN_DIR=$(dirname "$(dirname "$PWD")")
4
5 source "$ICN_DIR/env/lib/common.sh"
6
7 #create sample image
8 if true ; then
9     cat <<- EOF > /tmp/sample_image
10     This is a dummy file for testing.
11 EOF
12 fi
13
14 IMAGE_SIZE=$(ls -al /tmp/sample_image | awk '{print $5}')
15
16 if true ; then
17     cat <<- EOF > /tmp/sample.json
18     {
19         "owner":  "alpha",
20         "cluster_name": "beta",
21         "type": "container",
22         "image_name": "qwerty123",
23         "image_length": $IMAGE_SIZE,
24         "image_offset": 0,
25         "upload_complete":  false,
26         "description": {
27         "image_records":  [
28             {
29                 "image_record_name": "iuysdi1234",
30                 "repo": "icn",
31                 "tag":  "2"
32             }
33             ]
34         }
35     }
36 EOF
37 fi
38
39 cur_status=""
40
41 while [[ $cur_status != "Running" ]]; do
42
43     cur_status=$(kubectl get pods | grep bpa-api-deployment | awk '{print $3}')
44     if [[ $cur_status != "Running" ]]; then
45         echo "$(date +%H:%M:%S) - BPA-RESTful-API Pod status: $cur_status"
46     else
47         break
48
49     fi
50     if [[ $cur_status == "Err"* ]]; then
51         exit 1
52     fi
53     sleep 10
54 done
55
56
57 #Get CLusterIP
58 IP=$(kubectl get services | grep bpa-api-service | awk '{print $3}')
59
60 call_api -i -F "metadata=</tmp/sample.json;type=application/json" -F \
61 file=@/tmp/sample.json -X POST \
62 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images
63
64 call_api -i -X GET \
65 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123
66
67 call_api --request PATCH --data-binary "@/tmp/sample_image" \
68 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123 \
69 --header "Upload-Offset: 0" --header "Expect:" -i
70
71 call_api -i -X DELETE \
72 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123