-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathapi_base.test.js
104 lines (99 loc) · 3.3 KB
/
api_base.test.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
const gdal = require('../lib/gdal.js')
const assert = require('chai').assert
const path = require('path')
if (process.env.GDAL_DATA !== undefined) {
throw new Error(
'Sorry, this test requires that the GDAL_DATA environment option is not set'
)
}
describe('gdal', () => {
afterEach(gc)
describe('"lastError" property', () => {
describe('get()', () => {
it('should return null when no previous error', () => {
// note: this needs to be the first test run
assert.isNull(gdal.lastError)
})
it('should return an object normally', () => {
gdal._triggerCPLError()
assert.deepEqual(gdal.lastError, {
code: gdal.CPLE_AppDefined,
level: gdal.CE_Failure,
message: 'Mock error'
})
})
})
describe('set()', () => {
it('should allow reset by setting to null', () => {
gdal._triggerCPLError()
assert.equal(!!gdal.lastError, true)
gdal.lastError = null
assert.isNull(gdal.lastError)
})
it('should throw when not null', () => {
assert.throws(() => {
gdal.lastError = {}
}, /null/)
})
})
})
describe('"version" property', () => {
it('should exist', () => {
assert.match(gdal.version, /^\d+\.\d+\.\d+[a-zA-Z]*$/)
})
})
describe('"config" property', () => {
describe('get()', () => {
it('should not throw', () => {
gdal.config.get('CPL_LOG')
})
})
describe('set()', () => {
it('should set option', () => {
gdal.config.set('CPL_DEBUG', 'ON')
assert.equal(gdal.config.get('CPL_DEBUG'), 'ON')
gdal.config.set('CPL_DEBUG', null)
assert.isNull(gdal.config.get('CPL_DEBUG'))
})
})
describe('GDAL_DATA behavior', () => {
const data_path = path.resolve(__dirname, '../deps/libgdal/gdal/data')
it('should set GDAL_DATA config option to locally bundled path', () => {
assert.equal(gdal.config.get('GDAL_DATA'), data_path)
})
it('should respect GDAL_DATA environment over locally bundled path', (done) => {
process.env.GDAL_DATA = 'bogus'
const cp = require('child_process')
const command =
"\"var gdal = require('./lib/gdal.js'); console.log(gdal.config.get('GDAL_DATA'));\""
let execPath = process.execPath
if (process.platform === 'win32') {
// quotes to avoid errors like ''C:\Program' is not recognized as an internal or external command'
execPath = `"${execPath}"`
}
cp.exec(
`${execPath} ${[ '-e', command ].join(' ')}`,
{ env: { GDAL_DATA: 'bogus' } },
(err, stdout) => {
if (err) throw err
assert.equal(process.env.GDAL_DATA, stdout.trim())
done()
}
)
})
})
})
describe('decToDMS()', () => {
it('should throw when axis not provided', () => {
assert.throws(() => {
gdal.decToDMS(12.2)
})
})
it('should return correct result', () => {
assert.equal(gdal.decToDMS(14.12511, 'lat', 2), " 14d 7'30.40\"N")
assert.equal(gdal.decToDMS(14.12511, 'lat', 1), " 14d 7'30.4\"N")
assert.equal(gdal.decToDMS(14.12511, 'long', 2), " 14d 7'30.40\"E")
assert.equal(gdal.decToDMS(14.12511, 'long', 1), " 14d 7'30.4\"E")
})
})
})