Skip to content

Commit

Permalink
Add Travis CI config, make tests compatible with CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Shakeel Mohamed committed Feb 15, 2018
1 parent 94ded47 commit cf3a223
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
coverage
node_modules
npm-debug.log
config.json
test/config.json
.idea
docs
40 changes: 40 additions & 0 deletions .travis.yml
@@ -0,0 +1,40 @@
sudo: required

services:
- docker

notifications:
email: false

before_install:
# Create .splunkrc file with default credentials
- echo host=localhost >> $HOME/.splunkrc
- echo username=admin >> $HOME/.splunkrc
- echo password=changeme >> $HOME/.splunkrc
# Set SPLUNK_HOME
- export SPLUNK_HOME="/opt/splunk"
# Pull docker image
- docker pull splunk/splunk-sdk-travis-ci:$SPLUNK_VERSION
# Add DOCKER to iptables, 1/10 times this is needed, force 0 exit status
- sudo iptables -N DOCKER || true
# Start Docker container
- docker run -p 127.0.0.1:8089:8089 -p 127.0.0.1:8088:8088 -d splunk/splunk-sdk-travis-ci:$SPLUNK_VERSION
# curl Splunk until it returns valid data indicating it has been setup, try 20 times maximum
- for i in `seq 0 20`; do if curl --fail -k https://localhost:8089/services/server/info &> /dev/null; then break; fi; echo $i; sleep 1; done


language: node_js
node_js:
- "5.0"
- "4.2"
- "0.12"
- "0.10"

#Splunk versions can be set here
env:
- SPLUNK_VERSION=6.6-sdk
- SPLUNK_VERSION=7.0-sdk

# Test script, should return non 0 exit status if a test fails
script:
npm test
35 changes: 31 additions & 4 deletions test/test_env.js
Expand Up @@ -15,6 +15,8 @@
*/

var assert = require("assert");
var request = require("request");
var fs = require("fs");

/**
* Load test configuration from test/config.json
Expand All @@ -23,14 +25,39 @@ var assert = require("assert");
* {"token": "token-goes-here"}
*
*/
var configurationFile = require("./config.json");
var configurationFile = "./config.json";
var token = null;

describe("Environment Tests", function() {
describe("Splunk on localhost:8089 HEC", function() {
it("should be enabled", function(done) {
request.post("https://admin:changeme@localhost:8089/servicesNS/admin/splunk_httpinput/data/inputs/http/http/enable?output_mode=json", {strictSSL: false}, function(err) {
assert.ok(!err);
done();
});
});
it("should create a token in test/config.json", function(done) {
request.post("https://admin:changeme@localhost:8089/servicesNS/admin/splunk_httpinput/data/inputs/http?output_mode=json", {strictSSL: false, body: "name=splunk_logging" + Date.now()}, function(err, resp, body) {
assert.ok(!err);
var tokenStart = body.indexOf("\"token\":\"");
var tokenEnd = tokenStart + 36; // 36 = guid length
token = body.substring(tokenStart + 9, tokenEnd + 9); // 9 = prefix length of \"token\":\"
assert.strictEqual(token.length, 36);
done();
});
});
});
describe("config.json (test config file)", function() {
before("should be created from scratch", function() {
var obj = {token: token};
fs.writeFileSync(configurationFile, JSON.stringify(obj));
});
it("should at least have a token", function() {
assert.ok(configurationFile);
assert.ok(configurationFile.hasOwnProperty("token"));
assert.ok(configurationFile.token.length > 0);
var config = fs.readFileSync(configurationFile);
var configObj = JSON.parse(config);
assert.ok(configObj);
assert.ok(configObj.hasOwnProperty("token"));
assert.strictEqual(configObj.token.length, 36);
});
});
});
3 changes: 2 additions & 1 deletion test/test_send.js
Expand Up @@ -16,6 +16,7 @@

var SplunkLogger = require("../index").Logger;
var assert = require("assert");
var fs = require("fs");

/**
* Load test configuration from test/config.json
Expand All @@ -24,7 +25,7 @@ var assert = require("assert");
* {"token": "token-goes-here"}
*
*/
var configurationFile = require("./config.json");
var configurationFile = JSON.parse(fs.readFileSync("./config.json"));

var successBody = {
text: "Success",
Expand Down

0 comments on commit cf3a223

Please sign in to comment.