|
| 1 | +/** |
| 2 | + * This program and the accompanying materials are made available under the terms of the |
| 3 | + * Eclipse Public License v2.0 which accompanies this distribution, and is available at |
| 4 | + * https://www.eclipse.org/legal/epl-v20.html |
| 5 | + * |
| 6 | + * SPDX-License-Identifier: EPL-2.0 |
| 7 | + * |
| 8 | + * Copyright Contributors to the Zowe Project. |
| 9 | + * |
| 10 | + */ |
| 11 | + |
| 12 | +#include <cstddef> |
| 13 | +#include <ctime> |
| 14 | +#include <stdlib.h> |
| 15 | +#include <string> |
| 16 | +#include <vector> |
| 17 | +#include "ztest.hpp" |
| 18 | +#include "ztest.utils.hpp" |
| 19 | +#include "ztype.h" |
| 20 | +#include "zowex.test.hpp" |
| 21 | +#include "zowex.ds.test.hpp" |
| 22 | + |
| 23 | +using namespace std; |
| 24 | +using namespace ztst; |
| 25 | + |
| 26 | +const string zowex_command = "./../build-out/zowex"; |
| 27 | + |
| 28 | +void zowex_ds_tests() |
| 29 | +{ |
| 30 | + vector<string> _ds; |
| 31 | + describe("data-set", |
| 32 | + [&_ds]() -> void |
| 33 | + { |
| 34 | + afterAll( |
| 35 | + [&_ds]() -> void |
| 36 | + { |
| 37 | + TestLog("Deleting " + to_string(_ds.size()) + " data sets!"); |
| 38 | + for (vector<string>::iterator it = _ds.begin(); it != _ds.end(); ++it) |
| 39 | + { |
| 40 | + try |
| 41 | + { |
| 42 | + string command = zowex_command + " data-set delete " + *it; |
| 43 | + string response; |
| 44 | + TestLog(command); |
| 45 | + int rc = execute_command_with_output(command, response); |
| 46 | + ExpectWithContext(rc, response).ToBe(0); |
| 47 | + TestLog(response); |
| 48 | + Expect(response).ToContain("Data set '" + *it + "' deleted"); // ds deleted |
| 49 | + } |
| 50 | + catch (...) |
| 51 | + { |
| 52 | + TestLog("Failed to delete: " + *it); |
| 53 | + } |
| 54 | + } |
| 55 | + }); |
| 56 | + it("should display help", []() -> void |
| 57 | + { |
| 58 | + int rc = 0; |
| 59 | + string response; |
| 60 | + string command = zowex_command + " data-set"; |
| 61 | + rc = execute_command_with_output(command, response); |
| 62 | + ExpectWithContext(rc, response).ToBe(0); |
| 63 | + Expect(response).ToContain("create"); |
| 64 | + Expect(response).ToContain("delete"); |
| 65 | + Expect(response).ToContain("list"); // done |
| 66 | + }); |
| 67 | + describe("compress", |
| 68 | + []() -> void |
| 69 | + { |
| 70 | + it("should compress a data set", []() -> void {}); |
| 71 | + }); |
| 72 | + describe("create", |
| 73 | + [&_ds]() -> void |
| 74 | + { |
| 75 | + it("should create a data set with default attributes", |
| 76 | + [&_ds]() -> void |
| 77 | + { |
| 78 | + int rc = 0; |
| 79 | + string ds = get_random_ds(); |
| 80 | + _ds.push_back(ds); |
| 81 | + |
| 82 | + string response; |
| 83 | + string command = zowex_command + " data-set create " + ds; |
| 84 | + rc = execute_command_with_output(command, response); |
| 85 | + ExpectWithContext(rc, response).ToBe(0); |
| 86 | + Expect(response).ToContain("Data set created"); |
| 87 | + |
| 88 | + command = zowex_command + " data-set list " + ds + " -a --rfc"; |
| 89 | + rc = execute_command_with_output(command, response); |
| 90 | + ExpectWithContext(rc, response).ToBe(0); |
| 91 | + vector<string> tokens = split_rfc_response(response, ","); |
| 92 | + Expect(tokens[1]).ToBe("PS"); |
| 93 | + Expect(tokens[4]).ToBe("FB"); |
| 94 | + }); |
| 95 | + it("should create a data set - recfm:VB dsorg:PO", |
| 96 | + [&_ds]() -> void |
| 97 | + { |
| 98 | + int rc = 0; |
| 99 | + string ds = get_random_ds(); |
| 100 | + _ds.push_back(ds); |
| 101 | + |
| 102 | + string response; |
| 103 | + string command = zowex_command + " data-set create " + ds + " --recfm VB --dsorg PO"; |
| 104 | + rc = execute_command_with_output(command, response); |
| 105 | + ExpectWithContext(rc, response).ToBe(0); |
| 106 | + Expect(response).ToContain("Data set created"); |
| 107 | + |
| 108 | + command = zowex_command + " data-set list " + ds + " -a --rfc"; |
| 109 | + rc = execute_command_with_output(command, response); |
| 110 | + ExpectWithContext(rc, response).ToBe(0); |
| 111 | + vector<string> tokens = split_rfc_response(response, ","); |
| 112 | + Expect(tokens[1]).ToBe("PO"); |
| 113 | + Expect(tokens[4]).ToBe("VB"); |
| 114 | + }); |
| 115 | + |
| 116 | + it("should create a data set - dsorg: PO, primary: 10, secondary: 2, lrecl: 20, blksize:10, dirblk: 5, alcunit: CYL", |
| 117 | + [&_ds]() -> void |
| 118 | + { |
| 119 | + int rc = 0; |
| 120 | + string ds = get_random_ds(); |
| 121 | + _ds.push_back(ds); |
| 122 | + |
| 123 | + string response; |
| 124 | + string command = zowex_command + " data-set create " + ds + " --dsorg PO --primary 10 --secondary 2 --lrecl 20 --blksize 10 --dirblk 5 --alcunit CYL"; |
| 125 | + rc = execute_command_with_output(command, response); |
| 126 | + ExpectWithContext(rc, response).ToBe(0); |
| 127 | + Expect(response).ToContain("Data set created"); |
| 128 | + |
| 129 | + command = zowex_command + " data-set list " + ds + " -a --rfc"; |
| 130 | + rc = execute_command_with_output(command, response); |
| 131 | + ExpectWithContext(rc, response).ToBe(0); |
| 132 | + vector<string> tokens = split_rfc_response(response, ","); |
| 133 | + Expect(tokens[1]).ToBe("PO"); |
| 134 | + Expect(tokens[4]).ToBe("FB"); |
| 135 | + }); |
| 136 | + }); |
| 137 | + describe("create-adata", |
| 138 | + [&_ds]() -> void |
| 139 | + { |
| 140 | + it("should create a data set with default attributes", |
| 141 | + [&_ds]() -> void |
| 142 | + { |
| 143 | + int rc = 0; |
| 144 | + string ds = get_random_ds(); |
| 145 | + _ds.push_back(ds); |
| 146 | + |
| 147 | + string response; |
| 148 | + string command = zowex_command + " data-set create-adata " + ds; |
| 149 | + rc = execute_command_with_output(command, response); |
| 150 | + ExpectWithContext(rc, response).ToBe(0); |
| 151 | + Expect(response).ToContain("Data set created"); |
| 152 | + |
| 153 | + command = zowex_command + " data-set list " + ds + " -a --rfc"; |
| 154 | + rc = execute_command_with_output(command, response); |
| 155 | + ExpectWithContext(rc, response).ToBe(0); |
| 156 | + vector<string> tokens = split_rfc_response(response, ","); |
| 157 | + Expect(tokens[1]).ToContain("PO"); |
| 158 | + Expect(tokens[4]).ToBe("VB"); |
| 159 | + // lrecl = 32756 |
| 160 | + }); |
| 161 | + }); |
| 162 | + |
| 163 | + describe("create-fb", |
| 164 | + [&_ds]() -> void |
| 165 | + { |
| 166 | + it("should create a data set with default attributes", |
| 167 | + [&_ds]() -> void |
| 168 | + { |
| 169 | + int rc = 0; |
| 170 | + string ds = get_random_ds(); |
| 171 | + _ds.push_back(ds); |
| 172 | + |
| 173 | + string response; |
| 174 | + string command = zowex_command + " data-set create-fb " + ds; |
| 175 | + rc = execute_command_with_output(command, response); |
| 176 | + ExpectWithContext(rc, response).ToBe(0); |
| 177 | + Expect(response).ToContain("Data set created"); |
| 178 | + |
| 179 | + command = zowex_command + " data-set list " + ds + " -a --rfc"; |
| 180 | + rc = execute_command_with_output(command, response); |
| 181 | + ExpectWithContext(rc, response).ToBe(0); |
| 182 | + vector<string> tokens = split_rfc_response(response, ","); |
| 183 | + Expect(tokens[1]).ToContain("PO"); |
| 184 | + Expect(tokens[4]).ToBe("FB"); |
| 185 | + // lrecl = 80 |
| 186 | + }); |
| 187 | + }); |
| 188 | + describe("create-loadlib", |
| 189 | + [&_ds]() -> void |
| 190 | + { |
| 191 | + it("should create a data set with default attributes", |
| 192 | + [&_ds]() -> void |
| 193 | + { |
| 194 | + int rc = 0; |
| 195 | + string ds = get_random_ds(); |
| 196 | + _ds.push_back(ds); |
| 197 | + |
| 198 | + string response; |
| 199 | + string command = zowex_command + " data-set create-loadlib " + ds; |
| 200 | + rc = execute_command_with_output(command, response); |
| 201 | + ExpectWithContext(rc, response).ToBe(0); |
| 202 | + Expect(response).ToContain("Data set created"); |
| 203 | + |
| 204 | + command = zowex_command + " data-set list " + ds + " -a --rfc"; |
| 205 | + rc = execute_command_with_output(command, response); |
| 206 | + ExpectWithContext(rc, response).ToBe(0); |
| 207 | + vector<string> tokens = split_rfc_response(response, ","); |
| 208 | + Expect(tokens[1]).ToContain("PO"); |
| 209 | + Expect(tokens[4]).ToBe("U"); |
| 210 | + // lrecl = 0 |
| 211 | + }); |
| 212 | + }); |
| 213 | + describe("create-member", |
| 214 | + []() -> void |
| 215 | + { |
| 216 | + it("should create a data set with default attributes", []() -> void {}); |
| 217 | + }); |
| 218 | + describe("create-vb", |
| 219 | + [&_ds]() -> void |
| 220 | + { |
| 221 | + it("should create a data set with default attributes", |
| 222 | + [&_ds]() -> void |
| 223 | + { |
| 224 | + int rc = 0; |
| 225 | + string ds = get_random_ds(); |
| 226 | + _ds.push_back(ds); |
| 227 | + |
| 228 | + string response; |
| 229 | + string command = zowex_command + " data-set create-vb " + ds; |
| 230 | + rc = execute_command_with_output(command, response); |
| 231 | + ExpectWithContext(rc, response).ToBe(0); |
| 232 | + Expect(response).ToContain("Data set created"); |
| 233 | + |
| 234 | + command = zowex_command + " data-set list " + ds + " -a --rfc"; |
| 235 | + rc = execute_command_with_output(command, response); |
| 236 | + ExpectWithContext(rc, response).ToBe(0); |
| 237 | + vector<string> tokens = split_rfc_response(response, ","); |
| 238 | + Expect(tokens[1]).ToContain("PO"); |
| 239 | + Expect(tokens[4]).ToBe("VB"); |
| 240 | + // lrecl = 255 |
| 241 | + }); |
| 242 | + }); |
| 243 | + describe("delete", |
| 244 | + []() -> void {}); |
| 245 | + describe("list", |
| 246 | + []() -> void |
| 247 | + { |
| 248 | + it("should list a data set", |
| 249 | + []() |
| 250 | + { |
| 251 | + string data_set = "SYS1.MACLIB"; |
| 252 | + string response; |
| 253 | + string command = zowex_command + " data-set list " + data_set; |
| 254 | + int rc = execute_command_with_output(command, response); |
| 255 | + ExpectWithContext(rc, response).ToBe(0); |
| 256 | + }); |
| 257 | + it("should list data sets based on pattern and warn about listing too many members", |
| 258 | + []() |
| 259 | + { |
| 260 | + string dsn = "SYS1.CMDLIB"; |
| 261 | + string response; |
| 262 | + string pattern = "SYS1.*"; |
| 263 | + string command = zowex_command + " data-set list " + pattern + " --me 10"; |
| 264 | + int rc = execute_command_with_output(command, response); |
| 265 | + ExpectWithContext(rc, response).ToBe(RTNCD_WARNING); |
| 266 | + Expect(response).ToContain(dsn); |
| 267 | + }); |
| 268 | + }); |
| 269 | + describe("list-members", |
| 270 | + []() -> void |
| 271 | + { |
| 272 | + string data_set = "SYS1.MACLIB"; |
| 273 | + it("should list a member of a data set", |
| 274 | + [data_set]() |
| 275 | + { |
| 276 | + string response; |
| 277 | + string command = zowex_command + " data-set lm " + data_set + " --no-warn --me 1"; |
| 278 | + int rc = execute_command_with_output(command, response); |
| 279 | + ExpectWithContext(rc, response).ToBe(0); |
| 280 | + }); |
| 281 | + it("should warn when listing members of a data set with many members", |
| 282 | + [data_set]() |
| 283 | + { |
| 284 | + int rc = 0; |
| 285 | + string response; |
| 286 | + string command = zowex_command + " data-set lm " + data_set + " --me 1"; |
| 287 | + rc = execute_command_with_output(command, response); |
| 288 | + ExpectWithContext(rc, response).ToBe(RTNCD_WARNING); |
| 289 | + }); |
| 290 | + }); |
| 291 | + describe("restore", |
| 292 | + []() -> void {}); |
| 293 | + describe("view", |
| 294 | + []() -> void {}); |
| 295 | + describe("write", |
| 296 | + []() -> void {}); |
| 297 | + // describe("data set i/o tests", |
| 298 | + // []() -> void |
| 299 | + // { |
| 300 | + // it("should write and read from a data set", |
| 301 | + // []() |
| 302 | + // { |
| 303 | + // int rc = 0; |
| 304 | + // string user; |
| 305 | + // execute_command_with_output("whoami", user); |
| 306 | + // string data_set = TrimChars(user) + ".temp.temp.temp.temp.temp.temp.tmp"; |
| 307 | + // string member = "IEFBR14"; |
| 308 | + // string data_set_member = "\"" + data_set + "(" + member + ")\""; |
| 309 | + // string response; |
| 310 | + |
| 311 | + // // delete the data set if it exists |
| 312 | + // string del_command = zowex_command + " data-set delete " + data_set; |
| 313 | + // execute_command_with_output(del_command, response); |
| 314 | + |
| 315 | + // // create the data set |
| 316 | + // string command = zowex_command + " data-set create-fb " + data_set; |
| 317 | + // rc = execute_command_with_output(command, response); |
| 318 | + // ExpectWithContext(rc, response).ToBe(0); |
| 319 | + |
| 320 | + // string jcl = "//IEFBR14$ JOB (IZUACCT),TEST,REGION=0M\n//RUN EXEC PGM=IEFBR14"; |
| 321 | + |
| 322 | + // // Convert JCL to hex format and write to the data set |
| 323 | + // string hex_jcl = string_to_hex(jcl); |
| 324 | + // string write_command = "printf \"" + hex_jcl + "\" | " + zowex_command + " data-set write " + data_set_member; |
| 325 | + // rc = execute_command_with_output(write_command, response); |
| 326 | + // ExpectWithContext(rc, response).ToBe(0); |
| 327 | + |
| 328 | + // // read from the data set |
| 329 | + // string read_command = zowex_command + " data-set view " + data_set_member; |
| 330 | + // rc = execute_command_with_output(read_command, response); |
| 331 | + // ExpectWithContext(rc, response).ToBe(0); |
| 332 | + // Expect(TrimChars(response)).ToBe(jcl); |
| 333 | + |
| 334 | + // // delete the data set |
| 335 | + // execute_command_with_output(del_command, response); |
| 336 | + // }); |
| 337 | + // }); |
| 338 | + }); |
| 339 | +} |
0 commit comments