Adds unit tests and K8s artifacts
[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 curr_status=""
40
41 while [[ $curr_status != "Running" ]]; do
42
43     new_status=$(kubectl get pods | grep bpa-api-deployment | awk '{print $3}')
44     if [[ $new_status != $curr_status ]]; then
45         echo "$(date +%H:%M:%S) - BPA-RESTful-API Pod status: $new_status"
46         curr_status=$new_status
47         if [[ $new_status == "Running" ]]; then
48             break
49         fi
50     fi
51     if [[ $new_status == "Err"* ]]; then
52         exit 1
53     fi
54     sleep 10
55 done
56
57
58 #Get CLusterIP
59 IP=$(kubectl get services | grep bpa-api-service | awk '{print $3}')
60
61 call_api -i -F "metadata=</tmp/sample.json;type=application/json" -F \
62 file=@/tmp/sample.json -X POST \
63 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images
64
65 call_api -i -X GET \
66 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123
67
68 call_api --request PATCH --data-binary "@/tmp/sample_image" \
69 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123 \
70 --header "Upload-Offset: 0" --header "Expect:" -i
71
72 call_api -i -X DELETE \
73 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123