Revision 98b047dd src/Tests/cloud_test.c

View differences:

src/Tests/cloud_test.c
5 5
 *
6 6
 *  This is a small test program for the cloud interface
7 7
 *  To try the simple test: run it with
8
 *    ./cloud_test -c "provider=<cloud_provider>,<provider_opts>" [-g key | -p key=value | -n variant | -e ip:port]
8
 *    ./cloud_test -c "provider=<cloud_provider>,<provider_opts>" [-g key | -d key=value | -p key=value | -n variant | -e ip:port]
9 9
 *
10 10
 *    -g  GET key from cloud
11
 *    -d  GET key from cloud with default
11 12
 *    -p  PUT key=value on cloud
12 13
 *    -n  print the cloud node for the specified variant
13 14
 *    -e  check if ip:port references the cloud
......
33 34
#define PUT 1
34 35
#define GET_CLOUD_NODE 2
35 36
#define EQ_CLOUD_NODE 3
37
#define GETDEF 4
36 38

  
37 39
static const char *config;
38 40
static int operation;
......
47 49
  int o;
48 50
  char *temp;
49 51

  
50
  while ((o = getopt(argc, argv, "c:g:p:n:e:")) != -1) {
52
  while ((o = getopt(argc, argv, "c:g:d:p:n:e:")) != -1) {
51 53
    switch(o) {
52 54
    case 'c':
53 55
      config = strdup(optarg);
......
65 67
        exit(-1);
66 68
      }
67 69
      break;
68
      case 'g':
70
    case 'g':
69 71
        key =  strdup(optarg);
70 72
        break;
73
    case 'd':
74
      temp = strdup(optarg);
75
      operation = GETDEF;
76

  
77
      key = strsep(&optarg, "=");
78
      value = optarg;
79

  
80
      if (!value || !key){
81
        printf("Expected key=value for option -d");
82
        free(temp);
83
        exit(-1);
84
      }
85
      break;
71 86
    case 'n':
72 87
      operation = GET_CLOUD_NODE;
73 88
      variant = atoi(optarg);
......
140 155
      return 1;
141 156
    }
142 157
    break;
158
  case GETDEF:
143 159
  case GET:
144 160
    printf("Getting from cloud value for key \"%s\": ", key);
145 161
    memcpy(buffer, HEADER, strlen(HEADER));
146
    err = get_from_cloud(cloud, key, buffer, strlen(HEADER), 0);
162

  
163
    if (operation == GETDEF) {
164
      printf("(Using default value: \"%s\")", value);
165
      err = get_from_cloud_default(cloud, key, buffer, strlen(HEADER), 0,
166
                                   value, strlen(value), 0);
167
    } else {
168
      err = get_from_cloud(cloud, key, buffer, strlen(HEADER), 0);
169
    }
170

  
147 171
    if (err) {
148 172
      printf("Error performing the operation");
149 173
      return 1;
......
170 194
      printf("No response from cloud\n");
171 195
      return 1;
172 196
    } else {
197
      memset(buffer, 0, sizeof(buffer));
173 198
      err = recv_from_cloud(cloud, buffer, sizeof(buffer)-1);
174 199
      buffer[sizeof(buffer) - 1] = '\0';
175 200
      printf("No value for the specified key. Received: %s\n", buffer);

Also available in: Unified diff