@@ -46,6 +46,7 @@ var fakeUtil = extend({}, util, {
4646 'machineType' ,
4747 'network' ,
4848 'operation' ,
49+ 'project' ,
4950 'region' ,
5051 'rule' ,
5152 'service' ,
@@ -76,6 +77,7 @@ var fakePaginator = {
7677 'getMachineTypes' ,
7778 'getNetworks' ,
7879 'getOperations' ,
80+ 'getProject' ,
7981 'getRegions' ,
8082 'getRules' ,
8183 'getServices' ,
@@ -106,6 +108,10 @@ function FakeOperation() {
106108 this . calledWith_ = slice . call ( arguments ) ;
107109}
108110
111+ function FakeProject ( ) {
112+ this . calledWith_ = slice . call ( arguments ) ;
113+ }
114+
109115function FakeRegion ( ) {
110116 this . calledWith_ = slice . call ( arguments ) ;
111117 this . address = function ( ) { return { } ; } ;
@@ -155,6 +161,7 @@ describe('Compute', function() {
155161 './health-check.js' : FakeHealthCheck ,
156162 './network.js' : FakeNetwork ,
157163 './operation.js' : FakeOperation ,
164+ './project.js' : FakeProject ,
158165 './region.js' : FakeRegion ,
159166 './rule.js' : FakeRule ,
160167 './service.js' : FakeServiceClass ,
@@ -223,6 +230,7 @@ describe('Compute', function() {
223230 assert . strictEqual ( compute . getMachineTypesStream , 'getMachineTypes' ) ;
224231 assert . strictEqual ( compute . getNetworksStream , 'getNetworks' ) ;
225232 assert . strictEqual ( compute . getOperationsStream , 'getOperations' ) ;
233+ assert . strictEqual ( compute . getProjectStream , 'getProject' ) ;
226234 assert . strictEqual ( compute . getRegionsStream , 'getRegions' ) ;
227235 assert . strictEqual ( compute . getRulesStream , 'getRules' ) ;
228236 assert . strictEqual ( compute . getServicesStream , 'getServices' ) ;
@@ -1808,6 +1816,99 @@ describe('Compute', function() {
18081816 } ) ;
18091817 } ) ;
18101818
1819+ describe ( 'getProject' , function ( ) {
1820+ it ( 'should accept only a callback' , function ( done ) {
1821+ compute . request = function ( reqOpts ) {
1822+ assert . deepEqual ( reqOpts . qs , { } ) ;
1823+ done ( ) ;
1824+ } ;
1825+
1826+ compute . getProject ( assert . ifError ) ;
1827+ } ) ;
1828+
1829+ it ( 'should make the correct API request' , function ( done ) {
1830+ var options = { } ;
1831+
1832+ compute . request = function ( reqOpts ) {
1833+ assert . strictEqual ( reqOpts . uri , '' ) ;
1834+ assert . strictEqual ( reqOpts . qs , options ) ;
1835+ done ( ) ;
1836+ } ;
1837+
1838+ compute . getProject ( options , assert . ifError ) ;
1839+ } ) ;
1840+
1841+ describe ( 'error' , function ( ) {
1842+ var error = new Error ( 'Error.' ) ;
1843+ var apiResponse = { a : 'b' , c : 'd' } ;
1844+
1845+ beforeEach ( function ( ) {
1846+ compute . request = function ( reqOpts , callback ) {
1847+ callback ( error , apiResponse ) ;
1848+ } ;
1849+ } ) ;
1850+
1851+ it ( 'should execute callback with error & API response' , function ( done ) {
1852+ compute . getProject ( { } , function ( err , project , nextQuery , resp ) {
1853+ assert . strictEqual ( err , error ) ;
1854+ assert . strictEqual ( project , null ) ;
1855+ assert . strictEqual ( nextQuery , null ) ;
1856+ assert . strictEqual ( resp , apiResponse ) ;
1857+
1858+ done ( ) ;
1859+ } ) ;
1860+ } ) ;
1861+ } ) ;
1862+
1863+ describe ( 'success' , function ( ) {
1864+ var project = { name : PROJECT_ID } ;
1865+ var apiResponse = project ;
1866+
1867+ beforeEach ( function ( ) {
1868+ compute . request = function ( reqOpts , callback ) {
1869+ callback ( null , apiResponse ) ;
1870+ } ;
1871+ } ) ;
1872+
1873+ it ( 'should create Project object from the response' , function ( done ) {
1874+ compute . project = function ( name ) {
1875+ assert . strictEqual ( name , project . name ) ;
1876+ setImmediate ( done ) ;
1877+ return project ;
1878+ } ;
1879+
1880+ compute . getProject ( { } , ( err ) => {
1881+ assert . ifError ( err ) ;
1882+
1883+ compute . project ( PROJECT_ID ) ;
1884+ } ) ;
1885+ } ) ;
1886+
1887+ it ( 'shouldn\'t build a nextQuery' , function ( done ) {
1888+ var apiResponseWithNextPageToken = extend ( { } , apiResponse , {
1889+ nextPageToken : 'next-page-token'
1890+ } ) ;
1891+
1892+ var query = { a : 'b' , c : 'd' } ;
1893+ var originalQuery = extend ( { } , query ) ;
1894+
1895+ compute . request = function ( reqOpts , callback ) {
1896+ callback ( null , apiResponseWithNextPageToken ) ;
1897+ } ;
1898+
1899+ compute . getProject ( query , function ( err , project , nextQuery ) {
1900+ assert . ifError ( err ) ;
1901+
1902+ assert . deepEqual ( query , originalQuery ) ;
1903+
1904+ assert . strictEqual ( nextQuery , null ) ;
1905+
1906+ done ( ) ;
1907+ } ) ;
1908+ } ) ;
1909+ } ) ;
1910+ } ) ;
1911+
18111912 describe ( 'getRegions' , function ( ) {
18121913 it ( 'should work with only a callback' , function ( done ) {
18131914 compute . request = function ( reqOpts ) {
0 commit comments