|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import * as assert from 'assert'; |
| 18 | +import { |
| 19 | + isCompatible, |
| 20 | + _makeCompatibilityCheck, |
| 21 | +} from '../../src/internal/semver'; |
| 22 | +import { VERSION } from '../../src/version'; |
| 23 | + |
| 24 | +describe('Version Compatibility', () => { |
| 25 | + it('should be compatible if versions are equal', () => { |
| 26 | + assert.ok(isCompatible(VERSION)); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('throws if own version cannot be parsed', () => { |
| 30 | + assert.throws(() => { |
| 31 | + _makeCompatibilityCheck('this is not semver'); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('incompatible if other version cannot be parsed', () => { |
| 36 | + const check = _makeCompatibilityCheck('0.1.2'); |
| 37 | + assert.ok(!check('this is not semver')); |
| 38 | + }); |
| 39 | + |
| 40 | + describe('>= 1.x', () => { |
| 41 | + it('should be compatible if major and minor versions are equal', () => { |
| 42 | + const check = _makeCompatibilityCheck('1.2.3'); |
| 43 | + assert.ok(check('1.2.2')); |
| 44 | + assert.ok(check('1.2.2-alpha')); |
| 45 | + assert.ok(check('1.2.4')); |
| 46 | + assert.ok(check('1.2.4-alpha')); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should be compatible if major versions are equal and minor version is lesser', () => { |
| 50 | + const check = _makeCompatibilityCheck('1.2.3'); |
| 51 | + assert.ok(check('1.1.2')); |
| 52 | + assert.ok(check('1.1.2-alpha')); |
| 53 | + assert.ok(check('1.1.4')); |
| 54 | + assert.ok(check('1.1.4-alpha')); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should be incompatible if major versions do not match', () => { |
| 58 | + const check = _makeCompatibilityCheck('3.3.3'); |
| 59 | + assert.ok(!check('0.3.3')); |
| 60 | + assert.ok(!check('0.3.3')); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should be incompatible if major versions match but other minor version is greater than our minor version', () => { |
| 64 | + const check = _makeCompatibilityCheck('1.2.3'); |
| 65 | + assert.ok(!check('1.3.3-alpha')); |
| 66 | + assert.ok(!check('1.3.3')); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + describe('0.x', () => { |
| 71 | + it('should be compatible if minor and patch versions are equal', () => { |
| 72 | + const check = _makeCompatibilityCheck('0.1.2'); |
| 73 | + assert.ok(check('0.1.2')); |
| 74 | + assert.ok(check('0.1.2-alpha')); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should be compatible if minor versions are equal and patch version is lesser', () => { |
| 78 | + const check = _makeCompatibilityCheck('0.1.2'); |
| 79 | + assert.ok(check('0.1.1')); |
| 80 | + assert.ok(check('0.1.1-alpha')); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should be incompatible if minor versions do not match', () => { |
| 84 | + const check = _makeCompatibilityCheck('0.3.3'); |
| 85 | + assert.ok(!check('0.2.3')); |
| 86 | + assert.ok(!check('0.4.3')); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should be incompatible if minor versions do not match', () => { |
| 90 | + const check = _makeCompatibilityCheck('0.3.3'); |
| 91 | + assert.ok(!check('0.2.3')); |
| 92 | + assert.ok(!check('0.4.3')); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should be incompatible if minor versions match but other patch version is greater than our patch version', () => { |
| 96 | + const check = _makeCompatibilityCheck('0.3.3'); |
| 97 | + assert.ok(!check('0.3.4-alpha')); |
| 98 | + assert.ok(!check('0.3.4')); |
| 99 | + }); |
| 100 | + }); |
| 101 | +}); |
0 commit comments