1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Add tests for flat fact comparison

This commit is contained in:
Joe Fiorini 2015-06-11 12:22:58 -04:00
parent 9f6d93760e
commit aed496a069
2 changed files with 129 additions and 2 deletions

View File

@ -75,7 +75,7 @@ export default
value1: slottedValues.left,
value1IsAbsent: slottedValues.left === 'absent',
value2: slottedValues.right,
value2IsAbsent: slotFactValues.right === 'absent'
value2IsAbsent: slottedValues.right === 'absent'
};
});
}
@ -113,7 +113,7 @@ export default
if (slottedValues.left !== slottedValues.right) {
return {
keyName: key,
keyName: basisFact[nameKey],
value1: slottedValues.left,
value2: slottedValues.right
};

View File

@ -0,0 +1,127 @@
/* jshint node: true */
/* globals -expect, -_ */
import compareFacts from 'tower/system-tracking/compare-facts/flat';
var expect = require('chai').expect;
var _ = require('lodash');
global._ = _;
describe('CompareFacts.Flat', function() {
it('returns empty array with empty basis facts', function() {
var result = compareFacts({ facts: [] }, { facts: [] });
expect(result).to.deep.equal([]);
});
it('returns empty array when no differences', function() {
var result = compareFacts(
{ facts:
[{ 'name': 'foo',
'value': 'bar'
}]
},
{ facts:
[{ 'name': 'foo',
'value': 'bar'
}]
}, 'name', ['value']);
expect(result).to.deep.equal([]);
});
context('when both collections contain facts', function() {
it('includes each fact value when a compareKey differs', function() {
var result = compareFacts(
{ position: 'left',
facts:
[{ 'name': 'foo',
'value': 'bar'
}]
},
{ position: 'right',
facts:
[{ 'name': 'foo',
'value': 'baz'
}]
}, 'name', ['value']);
expect(result).to.deep.equal(
[{ displayKeyPath: 'foo',
nestingLevel: 0,
facts:
[{ keyName: 'foo',
value1: 'bar',
value2: 'baz'
}]
}]);
});
});
context('when value for nameKey is present in one collection but not the other', function() {
function factData(leftFacts) {
var facts = [{ position: 'left',
facts: leftFacts
},
{ position: 'right',
facts: []
}];
return facts;
}
beforeEach(function () {
});
it('uses "absent" for the missing value', function() {
var facts = factData([{ 'name': 'foo'
}]);
var result = compareFacts(facts[0], facts[1], 'name', ['value']);
expect(result).to.deep.equal(
[{ displayKeyPath: 'foo',
nestingLevel: 0,
facts:
[{ keyName: 'name',
value1: 'foo',
value1IsAbsent: false,
value2: 'absent',
value2IsAbsent: true
}]
}]);
});
it('includes all keys from basisFacts', function() {
var facts = factData([{ 'name': 'foo',
'value': 'bar'
}]);
var result = compareFacts(facts[0], facts[1], 'name', ['value']);
expect(result).to.deep.equal(
[{ displayKeyPath: 'foo',
nestingLevel: 0,
facts:
[{ keyName: 'name',
value1: 'foo',
value1IsAbsent: false,
value2: 'absent',
value2IsAbsent: true
},
{ keyName: 'value',
value1: 'bar',
value1IsAbsent: false,
value2: 'absent',
value2IsAbsent: true
}]
}]);
});
});
});