|
1 | 1 | const getObjectURL = require('../../VerifyBucketSproxydKeys/getObjectURL'); |
2 | 2 | const getBucketdURL = require('../../VerifyBucketSproxydKeys/getBucketdURL'); |
3 | 3 | const FindDuplicateSproxydKeys = require('../../VerifyBucketSproxydKeys/FindDuplicateSproxydKeys'); |
| 4 | +const validateLocations = require('../../VerifyBucketSproxydKeys/validateLocations'); |
4 | 5 |
|
5 | 6 | describe('verifyBucketSproxydKeys', () => { |
6 | 7 | test('getObjectURL', () => { |
@@ -77,4 +78,93 @@ describe('verifyBucketSproxydKeys', () => { |
77 | 78 | expect(finder.sproxydKeys).toEqual({ k7: 'obj9' }); |
78 | 79 | expect(finder.versionsWindow).toEqual({ 11: ['k7'], 12: ['k7'] }); |
79 | 80 | }); |
| 81 | + |
| 82 | + describe('validateLocations', () => { |
| 83 | + const key1 = { |
| 84 | + key: '8df148c188a7369ef6b632b08e9a2a867c065761', |
| 85 | + size: 2097, |
| 86 | + start: 0, |
| 87 | + dataStoreName: 'us-east-1', |
| 88 | + dataStoreType: 'scality', |
| 89 | + dataStoreETag: '1:35bf6d36c0c721deceda5d15fa642a18', |
| 90 | + }; |
| 91 | + const key2 = { |
| 92 | + key: '8df148c188a7369ef6b632b08e9a2a867c065762', |
| 93 | + size: 2098, |
| 94 | + start: 0, |
| 95 | + dataStoreName: 'us-east-1', |
| 96 | + dataStoreType: 'scality', |
| 97 | + dataStoreETag: '1:35bf6d36c0c721deceda5d15fa642a19', |
| 98 | + }; |
| 99 | + let status; |
| 100 | + let findDuplicateSproxydKeys; |
| 101 | + |
| 102 | + beforeEach(() => { |
| 103 | + status = { objectsScanned: 0, objectsWithBrokenMetadata: 0 }; |
| 104 | + findDuplicateSproxydKeys = { skipVersion: jest.fn() }; |
| 105 | + }); |
| 106 | + |
| 107 | + test('should return true for valid locations array', () => { |
| 108 | + const result = validateLocations('s3://bucket/key', [key1], status, findDuplicateSproxydKeys); |
| 109 | + |
| 110 | + expect(result).toEqual(true); |
| 111 | + expect(status.objectsScanned).toEqual(0); |
| 112 | + expect(status.objectsWithBrokenMetadata).toEqual(0); |
| 113 | + expect(findDuplicateSproxydKeys.skipVersion).not.toHaveBeenCalled(); |
| 114 | + }); |
| 115 | + |
| 116 | + test('should return true for multiple valid locations', () => { |
| 117 | + const result = validateLocations('s3://bucket/valid-key', [key1, key2], status, findDuplicateSproxydKeys); |
| 118 | + |
| 119 | + expect(result).toEqual(true); |
| 120 | + expect(status.objectsScanned).toEqual(0); |
| 121 | + expect(status.objectsWithBrokenMetadata).toEqual(0); |
| 122 | + expect(findDuplicateSproxydKeys.skipVersion).not.toHaveBeenCalled(); |
| 123 | + }); |
| 124 | + |
| 125 | + test('should return false for undefined locations', () => { |
| 126 | + const result = validateLocations('s3://bucket/broken-key', undefined, status, findDuplicateSproxydKeys); |
| 127 | + |
| 128 | + expect(result).toEqual(false); |
| 129 | + expect(status.objectsScanned).toEqual(1); |
| 130 | + expect(status.objectsWithBrokenMetadata).toEqual(1); |
| 131 | + expect(findDuplicateSproxydKeys.skipVersion).toHaveBeenCalledTimes(1); |
| 132 | + }); |
| 133 | + |
| 134 | + test('should return false for null locations', () => { |
| 135 | + const result = validateLocations('s3://bucket/null-key', null, status, findDuplicateSproxydKeys); |
| 136 | + |
| 137 | + expect(result).toEqual(false); |
| 138 | + expect(status.objectsScanned).toEqual(1); |
| 139 | + expect(status.objectsWithBrokenMetadata).toEqual(1); |
| 140 | + expect(findDuplicateSproxydKeys.skipVersion).toHaveBeenCalledTimes(1); |
| 141 | + }); |
| 142 | + |
| 143 | + test('should return false for empty array locations', () => { |
| 144 | + const result = validateLocations('s3://bucket/empty-key', [], status, findDuplicateSproxydKeys); |
| 145 | + |
| 146 | + expect(result).toEqual(false); |
| 147 | + expect(status.objectsScanned).toEqual(1); |
| 148 | + expect(status.objectsWithBrokenMetadata).toEqual(1); |
| 149 | + expect(findDuplicateSproxydKeys.skipVersion).toHaveBeenCalledTimes(1); |
| 150 | + }); |
| 151 | + |
| 152 | + test('should return false for non-array locations', () => { |
| 153 | + const result = validateLocations('s3://bucket/string-key', 'not-an-array', status, findDuplicateSproxydKeys); |
| 154 | + |
| 155 | + expect(result).toEqual(false); |
| 156 | + expect(status.objectsScanned).toEqual(1); |
| 157 | + expect(status.objectsWithBrokenMetadata).toEqual(1); |
| 158 | + expect(findDuplicateSproxydKeys.skipVersion).toHaveBeenCalledTimes(1); |
| 159 | + }); |
| 160 | + |
| 161 | + test('should return false for object instead of array', () => { |
| 162 | + const result = validateLocations('s3://bucket/object-key', { key: 'sproxyd-key' }, status, findDuplicateSproxydKeys); |
| 163 | + |
| 164 | + expect(result).toEqual(false); |
| 165 | + expect(status.objectsScanned).toEqual(1); |
| 166 | + expect(status.objectsWithBrokenMetadata).toEqual(1); |
| 167 | + expect(findDuplicateSproxydKeys.skipVersion).toHaveBeenCalledTimes(1); |
| 168 | + }); |
| 169 | + }); |
80 | 170 | }); |
0 commit comments