/
dockerhub.spec.js
70 lines (67 loc) · 1.68 KB
/
dockerhub.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require( "../setup" );
var proxyquire = require( "proxyquire" ).callThru();
var when = require( "when" );
var nock = require( "nock" );
var urlencode = require( "urlencode" );
var rp = require( "request-promise" );
var namesapce = "leankit";
var name = "cowpoke";
var tagToCheck = "tag1";
var validImage = namesapce + "/" + name + ":" + tagToCheck;
var invalidImage = namesapce + "/" + name + ":DNE";
var dockerhub = proxyquire( "../../src/dockerhub", {
"./util": {
getImageInfo: function( image ) {
if ( image === validImage ) {
return {
docker: {
repo: namesapce,
image: name,
tag: tagToCheck
}
};
} else {
return {
docker: {
repo: namesapce,
image: name,
tag: "DNE"
}
};
}
}
},
"request-promise": function( options ) {
if ( options.uri.indexOf( "auth.docker.io" ) !== -1 ) {
return when.resolve( {
token: "good to go"
} );
} else {
return when.resolve( {
tags: [ "tag", "tag1", "tag2", "tag3", "tag4", tagToCheck ]
} );
}
}
} );
describe( "Docker Hub API", function() {
var dockerapi;
var dockerAuth;
describe( "Check for an image?", function() {
describe( "Image exists", function() {
it( "should find that the image exists", function() {
function check( res ) {
return res.should.equal( true );
}
return dockerhub.checkExistance( validImage ).then( check );
} );
} );
describe( "Image does not exist", function() {
it( "should find that the image does not exist", function() {
function check( res ) {
return res.should.equal( false );
}
return dockerhub.checkExistance( invalidImage ).then( check );
} );
} );
} );
} );