[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / test / red / cli / lib / config_spec.js
1 /**
2  * Copyright 2014 IBM Corp.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  **/
16  
17 var should = require("should");
18 var sinon = require("sinon");
19 var fs = require("fs");
20
21 var config = require("../../../../red/cli/lib/config");
22
23 describe("cli config", function() {
24     afterEach(function() {
25         config.unload();
26     });
27     it('loads preferences when target referenced', sinon.test(function() {
28         this.stub(fs,"readFileSync",function() {
29             return '{"target":"http://example.com:1880"}'
30         });
31         config.target.should.eql("http://example.com:1880");
32     }));
33     it('provide default value for target', sinon.test(function() {
34         this.stub(fs,"readFileSync",function() {
35             return '{}'
36         });
37         config.target.should.eql("http://localhost:1880");
38     }));
39     it('saves preferences when target set', sinon.test(function() {
40         this.stub(fs,"readFileSync",function() {
41             return '{"target":"http://another.example.com:1880"}'
42         });
43         this.stub(fs,"writeFileSync",function() {});
44         
45         config.target.should.eql("http://another.example.com:1880");
46         config.target = "http://final.example.com:1880";
47         
48         fs.readFileSync.calledOnce.should.be.true;
49         fs.writeFileSync.calledOnce.should.be.true;
50         
51     }));
52         
53 });