-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMigratPlanner.down.js
111 lines (110 loc) · 5.19 KB
/
MigratPlanner.down.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var _ = require('lodash');
var assert = require('chai').assert;
var MigratProject = require('../lib/MigratProject.js');
var MigratPlanner = require('../lib/MigratPlanner.js');
var MigratState = require('../lib/MigratState.js');
var MigratPluginSystem = require('../lib/MigratPluginSystem.js');
var runlistVerifier = require('./utils/runlistVerifier.js');
var plugins = new MigratPluginSystem();
describe('MigratPlanner', function() {
describe('.down()', function(done) {
it('should return error if migrations cannot be read', function(done) {
var mockProject = new MigratProject({migrationsDir: __dirname + '/doesnotexist'});
var mockLocalState = new MigratState({});
var mockGlobalState = new MigratState({});
MigratPlanner.down(mockProject, plugins, mockGlobalState, mockLocalState, {to: 'something'}, function(err, runlist) {
assert.instanceOf(err, Error);
assert.match(err.message, /ENOENT/);
done();
});
});
it('should return error if "to" argument is missing', function(done) {
var mockProject = new MigratProject({migrationsDir: __dirname + '/fixtures/valid'});
var mockLocalState = new MigratState({});
var mockGlobalState = new MigratState({});
MigratPlanner.down(mockProject, plugins, mockGlobalState, mockLocalState, {}, function(err, runlist) {
assert.instanceOf(err, Error);
assert.match(err.message, /The down method requires the "to" option/);
done();
});
});
it('should return error if "to" argument invalid', function(done) {
var mockProject = new MigratProject({migrationsDir: __dirname + '/fixtures/valid'});
var mockLocalState = new MigratState({});
var mockGlobalState = new MigratState({});
MigratPlanner.down(mockProject, plugins, mockGlobalState, mockLocalState, {to: '1414006573678-doesnotexist.js'}, function(err, runlist) {
assert.instanceOf(err, Error);
assert.match(err.message, /was not found/);
done();
});
});
it('should return empty runlist for projects w/o any current state', function(done) {
var mockProject = new MigratProject({migrationsDir: __dirname + '/fixtures/valid'});
var mockLocalState = new MigratState({});
var mockGlobalState = new MigratState({});
MigratPlanner.down(mockProject, plugins, mockGlobalState, mockLocalState, {to: '1414006573623-first.js'}, runlistVerifier(done, [
['skip', '1414006573700-fourth.js'],
['skip', '1414006573679-third.all.js'],
['skip', '1414006573678-second.js']
]));
});
it('should return full runlist if all have been run before', function(done) {
var mockProject = new MigratProject({migrationsDir: __dirname + '/fixtures/valid'});
var mockLocalState = new MigratState({
'1414006573679-third.all.js': 1414006573679
});
var mockGlobalState = new MigratState({
'1414006573623-first.js': 1414006573623,
'1414006573678-second.js': 1414006573678,
'1414006573700-fourth.js': 1414006573700,
});
MigratPlanner.down(mockProject, plugins, mockGlobalState, mockLocalState, {to: '1414006573623-first.js'}, runlistVerifier(done, [
['down', '1414006573700-fourth.js'],
['down', '1414006573679-third.all.js'],
['down', '1414006573678-second.js']
]));
});
it('should return correct runlist when a node is partially migrated (simple)', function(done) {
var mockProject = new MigratProject({migrationsDir: __dirname + '/fixtures/valid'});
var mockLocalState = new MigratState({});
var mockGlobalState = new MigratState({
'1414006573678-second.js': 1414006573678,
'1414006573700-fourth.js': 1414006573700
});
MigratPlanner.down(mockProject, plugins, mockGlobalState, mockLocalState, {to: '1414006573623-first.js'}, runlistVerifier(done, [
['down', '1414006573700-fourth.js'],
['skip', '1414006573679-third.all.js'],
['down', '1414006573678-second.js']
]));
});
it('should return correct runlist when a migration has been executed on another node, but not the current', function(done) {
var mockProject = new MigratProject({migrationsDir: __dirname + '/fixtures/valid'});
var mockLocalState = new MigratState({});
var mockGlobalState = new MigratState({
'1414006573678-second.js': 1414006573678,
'1414006573700-fourth.js': 1414006573700,
'1414006573679-third.all.js': 1414006573679 // it should ignore this
});
MigratPlanner.down(mockProject, plugins, mockGlobalState, mockLocalState, {to: '1414006573623-first.js'}, runlistVerifier(done, [
['down', '1414006573700-fourth.js'],
['skip', '1414006573679-third.all.js'],
['down', '1414006573678-second.js']
]));
});
it('it should return corrent runlist when containing a migration that has already run locally', function(done) {
var mockProject = new MigratProject({migrationsDir: __dirname + '/fixtures/valid'});
var mockLocalState = new MigratState({
'1414006573679-third.all.js': 1414006573679
});
var mockGlobalState = new MigratState({
'1414006573678-second.js': 1414006573678,
'1414006573700-fourth.js': 1414006573700,
});
MigratPlanner.down(mockProject, plugins, mockGlobalState, mockLocalState, {to: '1414006573623-first.js'}, runlistVerifier(done, [
['down', '1414006573700-fourth.js'],
['down', '1414006573679-third.all.js'],
['down', '1414006573678-second.js']
]));
});
});
});