|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const test = require('tape'); |
| 4 | + |
| 5 | +test('test ingress, already created', (t) => { |
| 6 | + const ingress = require('../lib/ingress'); |
| 7 | + const resource = { |
| 8 | + apiVersion: 'v1', |
| 9 | + kind: 'Service', |
| 10 | + metadata: { |
| 11 | + name: 'my route' |
| 12 | + }, |
| 13 | + spec: { |
| 14 | + host: '192.168.1.1' |
| 15 | + } |
| 16 | + }; |
| 17 | + |
| 18 | + const config = { |
| 19 | + projectName: 'test-project', |
| 20 | + context: { |
| 21 | + namespace: 'namespace' |
| 22 | + }, |
| 23 | + projectVersion: '1.0.0', |
| 24 | + openshiftRestClient: { |
| 25 | + ingress: |
| 26 | + { |
| 27 | + find: (name) => { |
| 28 | + if (name !== resource.metadata.name) { |
| 29 | + t.fail('name argument does not match the resource.metadata.name'); |
| 30 | + } |
| 31 | + return { code: 200, metadata: { name: 'ingress' } }; |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + }; |
| 36 | + |
| 37 | + const p = ingress(config, resource).then((service) => { |
| 38 | + t.equal(service.code, 200, 'ingress response code should be 200'); |
| 39 | + t.end(); |
| 40 | + }); |
| 41 | + |
| 42 | + t.equal(p instanceof Promise, true, 'should return a Promise'); |
| 43 | +}); |
| 44 | + |
| 45 | +test('test ingress, not created', (t) => { |
| 46 | + const ingress = require('../lib/ingress'); |
| 47 | + const resource = { |
| 48 | + apiVersion: 'extensions/v1beta1', |
| 49 | + kind: 'Ingress', |
| 50 | + metadata: { |
| 51 | + name: 'nodejs-istio-circuit-breaker-gateway' |
| 52 | + } |
| 53 | + }; |
| 54 | + |
| 55 | + const config = { |
| 56 | + projectName: 'test-project', |
| 57 | + context: { |
| 58 | + namespace: 'namespace' |
| 59 | + }, |
| 60 | + projectVersion: '1.0.0', |
| 61 | + openshiftRestClient: { |
| 62 | + ingress: |
| 63 | + { |
| 64 | + find: (name) => { |
| 65 | + return { code: 404 }; |
| 66 | + }, |
| 67 | + create: ingress => ingress |
| 68 | + } |
| 69 | + } |
| 70 | + }; |
| 71 | + |
| 72 | + const p = ingress(config, resource).then((ingress) => { |
| 73 | + t.equal(ingress.kind, 'Ingress', 'is a Ingress Kind'); |
| 74 | + t.equal(ingress.metadata.name, 'nodejs-istio-circuit-breaker-gateway', 'metadata.name should be nodejs-istio-circuit-breaker-gateway'); |
| 75 | + t.end(); |
| 76 | + }); |
| 77 | + |
| 78 | + t.equal(p instanceof Promise, true, 'should return a Promise'); |
| 79 | +}); |
0 commit comments