github.com/jbking/gohan@v0.0.0-20151217002006-b41ccf1c2a96/extension/framework/runner/test_data/mock_transactions.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 17 var SCHEMAS = ["./schema.yaml"]; 18 var PATH = "/v1.0/networks"; 19 20 var network1 = { 21 "id": "abc", 22 "name": "net", 23 "tenant_id": "tenant", 24 "shared": false, 25 "admin_state_up": false 26 }; 27 28 function testMockTransactions() { 29 var transaction = MockTransaction(); 30 var resources = gohan_db_list(transaction, "network", {}); 31 if (JSON.stringify(resources) != JSON.stringify([])) { 32 Fail("Invalid resources - expected an empty array"); 33 } 34 35 resp = gohan_db_create(transaction, "network", network1); 36 37 resources = gohan_db_list(transaction, "network", {}); 38 if (JSON.stringify(resources) !== JSON.stringify([network1])) { 39 Fail("Invalid resources in first transaction - expected %s, received %s", 40 JSON.stringify([network1]), JSON.stringify(resources)); 41 } 42 43 CommitMockTransaction(); 44 45 transaction = MockTransaction(); 46 47 resources = gohan_db_list(transaction, "network", {}); 48 if (JSON.stringify(resources) !== JSON.stringify([network1])) { 49 Fail("Invalid resources in second transaction - expected %s, received %s", 50 JSON.stringify([network1]), JSON.stringify(resources)); 51 } 52 }