stackviz/test/unit/services/test-dataset.js
Tim Buckley d27c01fb6a Add new configuration file format
This enables a new "artifact"-based configuration file format,
intended to work natively with the deployer and to aid future efforts
to visualize additional data sources.

Among other tweaks, dataset indices are no longer used as the primary
differentiator between data files, and instead artifact names (such as
`testrepository.subunit`) are used to group related artfacts of various
types, such as 'subunit', 'subunit-stats', and 'subunit-details'.

Additionally, datasets and artifacts now have access to substantially
more metadata about the job that generated the output data. In future
patches, this metadata will be used to display and link to additional
information about visualized data. This metadata is made available
automatically by the deployer, and can be optionally gathered from
environment variables when using `stackviz-export` via a new `--env`
flag.

Change-Id: I3e16cc314624a1b7b4f6bf43fa4d5cdeedcdba0c
2016-04-21 16:21:52 -06:00

97 lines
2.8 KiB
JavaScript

/*global angular */
'use strict';
describe('Unit: DatasetService', function() {
var service, httpBackend;
var mockConfig = {
"deployer": false,
"datasets": [{
"status": null, "ci_username": null, "pipeline": null,
"change_project": null, "name": null, "url": null,
"change_id": null, "change_subject": null, "revision": null,
"artifacts": [
{
"artifact_type": "dstat", "path": "dstat.csv", "primary": false,
"content_type": "text/csv", "artifact_name": "dstat-csv.txt"
}, {
"artifact_type": "subunit", "primary": true,
"path": "testrepository.subunit-0-raw.json",
"content_type": "application/json",
"artifact_name": "testrepository.subunit"
}, {
"artifact_type": "subunit-details", "primary": false,
"path": "testrepository.subunit-0-details.json",
"content_type": "application/json",
"artifact_name": "testrepository.subunit"
}, {
"artifact_type": "subunit-stats", "primary": false,
"path": "testrepository.subunit-0-stats.json",
"content_type": "application/json",
"artifact_name": "testrepository.subunit"
}
]
}]
};
beforeEach(function() {
// instantiate the app module
angular.mock.module('app');
// mock the service
angular.mock.inject(function(datasetService, $httpBackend) {
service = datasetService;
httpBackend = $httpBackend;
httpBackend.whenGET("data/config.json").respond(mockConfig);
});
});
it('should exist', function() {
expect(service).toBeDefined();
});
it('should return the loaded configuration', function() {
service.config().then(function(config) {
expect(config.config).toEqual(mockConfig);
});
httpBackend.flush();
});
it('should only have valid primary artifacts', function() {
service.groups(true).then(function(groups) {
expect(groups.length).toEqual(1);
expect(groups).toContain('testrepository.subunit');
}, function() {
fail('callback should return');
});
httpBackend.flush();
});
it('should find all artifacts matching a particular name', function() {
service.artifacts('testrepository.subunit').then(function(artifacts) {
expect(artifacts.length).toEqual(3);
}, function() {
fail('callback should return');
});
httpBackend.flush();
});
it('should load an artifact', function() {
httpBackend.whenGET('data/testrepository.subunit-0-raw.json').respond({
mock: true
});
service.artifact('testrepository.subunit', 'subunit').then(function(resp) {
expect(resp.data).toEqual({ mock: true });
}, function(ex) {
fail('promise should return successfully: ' + ex);
});
httpBackend.flush();
});
});