|
| 1 | +import { buildServicesForEntry } from './build-services'; |
| 2 | +import { PackageMatrixVersion } from '../matrix/matrix-type'; |
| 3 | + |
| 4 | +const createTestEntry = (overrides: Partial<PackageMatrixVersion> = {}): PackageMatrixVersion => ({ |
| 5 | + magento: 'magento/project-community-edition:2.4.7', |
| 6 | + php: '8.3', |
| 7 | + composer: '2.7.4', |
| 8 | + mysql: 'mysql:8.4', |
| 9 | + elasticsearch: 'elasticsearch:8.11.4', |
| 10 | + opensearch: 'opensearchproject/opensearch:2.19.1', |
| 11 | + rabbitmq: 'rabbitmq:4.0-management', |
| 12 | + redis: 'redis:7.2', |
| 13 | + varnish: 'varnish:7.5', |
| 14 | + valkey: 'valkey:8.0', |
| 15 | + nginx: 'nginx:1.26', |
| 16 | + os: 'ubuntu-latest', |
| 17 | + release: '2024-04-09T00:00:00+0000', |
| 18 | + eol: '2027-04-09T00:00:00+0000', |
| 19 | + ...overrides |
| 20 | +}); |
| 21 | + |
| 22 | +describe('buildServicesForEntry', () => { |
| 23 | + describe('search engine selection', () => { |
| 24 | + it('should prefer opensearch when both are available', () => { |
| 25 | + const entry = createTestEntry(); |
| 26 | + const services = buildServicesForEntry(entry); |
| 27 | + |
| 28 | + expect(services.opensearch).toBeDefined(); |
| 29 | + expect(services.opensearch.image).toBe('opensearchproject/opensearch:2.19.1'); |
| 30 | + expect(services.elasticsearch).toBeUndefined(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should fall back to elasticsearch when opensearch is empty', () => { |
| 34 | + const entry = createTestEntry({ opensearch: '' }); |
| 35 | + const services = buildServicesForEntry(entry); |
| 36 | + |
| 37 | + expect(services.elasticsearch).toBeDefined(); |
| 38 | + expect(services.elasticsearch.image).toBe('elasticsearch:8.11.4'); |
| 39 | + expect(services.opensearch).toBeUndefined(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should not include search engine when neither is available', () => { |
| 43 | + const entry = createTestEntry({ opensearch: '', elasticsearch: '' }); |
| 44 | + const services = buildServicesForEntry(entry); |
| 45 | + |
| 46 | + expect(services.opensearch).toBeUndefined(); |
| 47 | + expect(services.elasticsearch).toBeUndefined(); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('cache selection', () => { |
| 52 | + it('should prefer valkey when both are available', () => { |
| 53 | + const entry = createTestEntry(); |
| 54 | + const services = buildServicesForEntry(entry); |
| 55 | + |
| 56 | + expect(services.valkey).toBeDefined(); |
| 57 | + expect(services.valkey.image).toBe('valkey:8.0'); |
| 58 | + expect(services.redis).toBeUndefined(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should fall back to redis when valkey is empty', () => { |
| 62 | + const entry = createTestEntry({ valkey: '' }); |
| 63 | + const services = buildServicesForEntry(entry); |
| 64 | + |
| 65 | + expect(services.redis).toBeDefined(); |
| 66 | + expect(services.redis.image).toBe('redis:7.2'); |
| 67 | + expect(services.valkey).toBeUndefined(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should not include cache when neither is available', () => { |
| 71 | + const entry = createTestEntry({ valkey: '', redis: '' }); |
| 72 | + const services = buildServicesForEntry(entry); |
| 73 | + |
| 74 | + expect(services.valkey).toBeUndefined(); |
| 75 | + expect(services.redis).toBeUndefined(); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe('mysql configuration', () => { |
| 80 | + it('should include mysql when available', () => { |
| 81 | + const entry = createTestEntry(); |
| 82 | + const services = buildServicesForEntry(entry); |
| 83 | + |
| 84 | + expect(services.mysql).toBeDefined(); |
| 85 | + expect(services.mysql.image).toBe('mysql:8.4'); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should not include mysql when empty', () => { |
| 89 | + const entry = createTestEntry({ mysql: '' }); |
| 90 | + const services = buildServicesForEntry(entry); |
| 91 | + |
| 92 | + expect(services.mysql).toBeUndefined(); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should include correct mysql env configuration', () => { |
| 96 | + const entry = createTestEntry(); |
| 97 | + const services = buildServicesForEntry(entry); |
| 98 | + |
| 99 | + expect(services.mysql.env).toEqual({ |
| 100 | + MYSQL_DATABASE: 'magento_integration_tests', |
| 101 | + MYSQL_USER: 'user', |
| 102 | + MYSQL_PASSWORD: 'password', |
| 103 | + MYSQL_ROOT_PASSWORD: 'rootpassword' |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + it('should include correct mysql ports', () => { |
| 108 | + const entry = createTestEntry(); |
| 109 | + const services = buildServicesForEntry(entry); |
| 110 | + |
| 111 | + expect(services.mysql.ports).toEqual(['3306:3306']); |
| 112 | + }); |
| 113 | + |
| 114 | + it('should include mysql health check options', () => { |
| 115 | + const entry = createTestEntry(); |
| 116 | + const services = buildServicesForEntry(entry); |
| 117 | + |
| 118 | + expect(services.mysql.options).toContain('--health-cmd'); |
| 119 | + expect(services.mysql.options).toContain('mysqladmin ping'); |
| 120 | + }); |
| 121 | + }); |
| 122 | + |
| 123 | + describe('rabbitmq configuration', () => { |
| 124 | + it('should include rabbitmq when available', () => { |
| 125 | + const entry = createTestEntry(); |
| 126 | + const services = buildServicesForEntry(entry); |
| 127 | + |
| 128 | + expect(services.rabbitmq).toBeDefined(); |
| 129 | + expect(services.rabbitmq.image).toBe('rabbitmq:4.0-management'); |
| 130 | + }); |
| 131 | + |
| 132 | + it('should not include rabbitmq when empty', () => { |
| 133 | + const entry = createTestEntry({ rabbitmq: '' }); |
| 134 | + const services = buildServicesForEntry(entry); |
| 135 | + |
| 136 | + expect(services.rabbitmq).toBeUndefined(); |
| 137 | + }); |
| 138 | + |
| 139 | + it('should include correct rabbitmq env configuration', () => { |
| 140 | + const entry = createTestEntry(); |
| 141 | + const services = buildServicesForEntry(entry); |
| 142 | + |
| 143 | + expect(services.rabbitmq.env).toEqual({ |
| 144 | + RABBITMQ_DEFAULT_USER: 'guest', |
| 145 | + RABBITMQ_DEFAULT_PASS: 'guest' |
| 146 | + }); |
| 147 | + }); |
| 148 | + |
| 149 | + it('should include correct rabbitmq ports', () => { |
| 150 | + const entry = createTestEntry(); |
| 151 | + const services = buildServicesForEntry(entry); |
| 152 | + |
| 153 | + expect(services.rabbitmq.ports).toEqual(['5672:5672']); |
| 154 | + }); |
| 155 | + }); |
| 156 | + |
| 157 | + describe('opensearch configuration', () => { |
| 158 | + it('should include correct opensearch env configuration', () => { |
| 159 | + const entry = createTestEntry(); |
| 160 | + const services = buildServicesForEntry(entry); |
| 161 | + |
| 162 | + expect(services.opensearch.env).toEqual({ |
| 163 | + 'discovery.type': 'single-node', |
| 164 | + 'DISABLE_INSTALL_DEMO_CONFIG': 'true', |
| 165 | + 'DISABLE_SECURITY_PLUGIN': 'true' |
| 166 | + }); |
| 167 | + }); |
| 168 | + |
| 169 | + it('should include correct opensearch ports', () => { |
| 170 | + const entry = createTestEntry(); |
| 171 | + const services = buildServicesForEntry(entry); |
| 172 | + |
| 173 | + expect(services.opensearch.ports).toEqual(['9200:9200']); |
| 174 | + }); |
| 175 | + |
| 176 | + it('should include opensearch health check options', () => { |
| 177 | + const entry = createTestEntry(); |
| 178 | + const services = buildServicesForEntry(entry); |
| 179 | + |
| 180 | + expect(services.opensearch.options).toContain('--health-cmd'); |
| 181 | + expect(services.opensearch.options).toContain('curl'); |
| 182 | + }); |
| 183 | + }); |
| 184 | + |
| 185 | + describe('elasticsearch configuration', () => { |
| 186 | + it('should include correct elasticsearch env configuration', () => { |
| 187 | + const entry = createTestEntry({ opensearch: '' }); |
| 188 | + const services = buildServicesForEntry(entry); |
| 189 | + |
| 190 | + expect(services.elasticsearch.env).toEqual({ |
| 191 | + 'discovery.type': 'single-node', |
| 192 | + 'xpack.security.enabled': 'false', |
| 193 | + 'xpack.security.http.ssl.enabled': 'false', |
| 194 | + 'xpack.security.transport.ssl.enabled': 'false' |
| 195 | + }); |
| 196 | + }); |
| 197 | + |
| 198 | + it('should include correct elasticsearch ports', () => { |
| 199 | + const entry = createTestEntry({ opensearch: '' }); |
| 200 | + const services = buildServicesForEntry(entry); |
| 201 | + |
| 202 | + expect(services.elasticsearch.ports).toEqual(['9200:9200']); |
| 203 | + }); |
| 204 | + }); |
| 205 | + |
| 206 | + describe('cache configuration', () => { |
| 207 | + it('should include correct valkey ports', () => { |
| 208 | + const entry = createTestEntry(); |
| 209 | + const services = buildServicesForEntry(entry); |
| 210 | + |
| 211 | + expect(services.valkey.ports).toEqual(['6379:6379']); |
| 212 | + }); |
| 213 | + |
| 214 | + it('should include correct redis ports', () => { |
| 215 | + const entry = createTestEntry({ valkey: '' }); |
| 216 | + const services = buildServicesForEntry(entry); |
| 217 | + |
| 218 | + expect(services.redis.ports).toEqual(['6379:6379']); |
| 219 | + }); |
| 220 | + }); |
| 221 | + |
| 222 | + describe('complete service output', () => { |
| 223 | + it('should build all services when all are available', () => { |
| 224 | + const entry = createTestEntry(); |
| 225 | + const services = buildServicesForEntry(entry); |
| 226 | + |
| 227 | + expect(Object.keys(services)).toHaveLength(4); |
| 228 | + expect(services.mysql).toBeDefined(); |
| 229 | + expect(services.opensearch).toBeDefined(); |
| 230 | + expect(services.rabbitmq).toBeDefined(); |
| 231 | + expect(services.valkey).toBeDefined(); |
| 232 | + }); |
| 233 | + |
| 234 | + it('should handle entry with minimal services', () => { |
| 235 | + const entry = createTestEntry({ |
| 236 | + mysql: '', |
| 237 | + elasticsearch: '', |
| 238 | + opensearch: '', |
| 239 | + rabbitmq: '', |
| 240 | + redis: '', |
| 241 | + valkey: '' |
| 242 | + }); |
| 243 | + const services = buildServicesForEntry(entry); |
| 244 | + |
| 245 | + expect(Object.keys(services)).toHaveLength(0); |
| 246 | + }); |
| 247 | + }); |
| 248 | +}); |
0 commit comments