github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/extension/framework/runner/test_data/gohan_builtins.js (about) 1 // Copyright (C) 2015 NTT Innovation Institute, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 // implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 var SCHEMA_INCLUDES = []; 17 var SCHEMAS = ["./schema.yaml"]; 18 var PATH = "/v1.0/networks"; 19 20 function testGohanBuiltins() { 21 var transaction = MockTransaction(); 22 var network1 = { 23 "id": "abc", 24 "name": "net", 25 "tenant_id": "tenant", 26 "shared": false, 27 "admin_state_up": false 28 }; 29 var network2 = { 30 "id": "def", 31 "name": "nonet", 32 "tenant_id": "tenant", 33 "shared": false, 34 "admin_state_up": false 35 }; 36 37 var resources = gohan_db_list(transaction, "network", {}); 38 if (JSON.stringify(resources) != JSON.stringify([])) { 39 Fail("Invalid resources - expected an empty array"); 40 } 41 42 var resp = gohan_db_create(transaction, "network", network1); 43 if (!_.isUndefined(resp.error)) { 44 Fail("Failed to create a resource: %s", JSON.stringify(resp.error)); 45 } 46 resp = gohan_db_create(transaction, "network", network2); 47 if (!_.isUndefined(resp.error)) { 48 Fail("Failed to create a resource: %s", JSON.stringify(resp.error)); 49 } 50 51 resources = gohan_db_list(transaction, "network", {}); 52 if (JSON.stringify(resources) !== JSON.stringify([network1, network2])) { 53 Fail("Invalid resources - expected %s, received %s", 54 JSON.stringify([network1, network2]), JSON.stringify(resources)); 55 } 56 57 network1.admin_state_up = true; 58 gohan_db_update(transaction, "network", network1); 59 var resource = gohan_db_fetch(transaction, "network", "abc", "tenant"); 60 61 if (JSON.stringify(resource) !== JSON.stringify(network1)) { 62 FAIL("Invalid resource - expected %s, received %s", 63 JSON.stringify(network1), JSON.stringify(resource)); 64 } 65 66 gohan_db_delete(transaction, "network", network2.id); 67 resources = gohan_db_list(transaction, "network", {}); 68 if (JSON.stringify(resources) !== JSON.stringify([network1])) { 69 Fail("Invalid resources - expected %s, received %s", 70 JSON.stringify([network1]), JSON.stringify(resources)); 71 } 72 73 gohan_db_delete(transaction, "network", network1.id); 74 resources = gohan_db_list(transaction, "network", {}); 75 if (JSON.stringify(resources) != JSON.stringify([])) { 76 Fail("Invalid resources - expected an empty array"); 77 } 78 }