|
| 1 | +var expect = require('chai').expect; |
| 2 | +var aksDiagnosticLogsEnabled = require('./aksDiagnosticLogsEnabled'); |
| 3 | + |
| 4 | +const clusters = [ |
| 5 | + { |
| 6 | + "id": "/subscriptions/123-test/resourcegroups/ABSBAKS2/providers/Microsoft.ContainerService/managedClusters/absbaks2", |
| 7 | + }, |
| 8 | +]; |
| 9 | + |
| 10 | + |
| 11 | +const diagnosticSettings = [ |
| 12 | + { |
| 13 | + id: '/subscriptions/234/myrg/providers/Microsoft.ContainerService/managedClusters/absbaks2/providers/microsoft.insights/diagnosticSettings/test-setting', |
| 14 | + type: 'Microsoft.Insights/diagnosticSettings', |
| 15 | + name: 'server-setting', |
| 16 | + location: 'eastus', |
| 17 | + kind: null, |
| 18 | + tags: null, |
| 19 | + eventHubName: null, |
| 20 | + metrics: [], |
| 21 | + logs: [ |
| 22 | + { |
| 23 | + "category": null, |
| 24 | + "categoryGroup": "allLogs", |
| 25 | + "enabled": true, |
| 26 | + "retentionPolicy": { |
| 27 | + "enabled": false, |
| 28 | + "days": 0 |
| 29 | + } |
| 30 | + }, |
| 31 | + { |
| 32 | + "category": null, |
| 33 | + "categoryGroup": "audit", |
| 34 | + "enabled": false, |
| 35 | + "retentionPolicy": { |
| 36 | + "enabled": false, |
| 37 | + "days": 0 |
| 38 | + } |
| 39 | + } |
| 40 | + ], |
| 41 | + logAnalyticsDestinationType: null |
| 42 | + } |
| 43 | +]; |
| 44 | + |
| 45 | +const createCache = (clusters, ds) => { |
| 46 | + const id = clusters && clusters.length ? clusters[0].id : null; |
| 47 | + return { |
| 48 | + managedClusters: { |
| 49 | + list: { |
| 50 | + 'eastus': { |
| 51 | + data: clusters |
| 52 | + } |
| 53 | + } |
| 54 | + }, |
| 55 | + diagnosticSettings: { |
| 56 | + listByAksClusters: { |
| 57 | + 'eastus': { |
| 58 | + [id]: { |
| 59 | + data: ds |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + }, |
| 65 | + }; |
| 66 | +}; |
| 67 | + |
| 68 | +const createErrorCache = () => { |
| 69 | + return { |
| 70 | + managedClusters: { |
| 71 | + list: { |
| 72 | + 'eastus': {} |
| 73 | + } |
| 74 | + } |
| 75 | + }; |
| 76 | +}; |
| 77 | + |
| 78 | +describe('aksDiagnosticLogsEnabled', function() { |
| 79 | + describe('run', function() { |
| 80 | + it('should give passing result if no clusters', function(done) { |
| 81 | + const cache = createCache([]); |
| 82 | + aksDiagnosticLogsEnabled.run(cache, {}, (err, results) => { |
| 83 | + expect(results.length).to.equal(1); |
| 84 | + expect(results[0].status).to.equal(0); |
| 85 | + expect(results[0].message).to.include('No existing Kubernetes clusters'); |
| 86 | + expect(results[0].region).to.equal('eastus'); |
| 87 | + done(); |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should give unknown result if unable to query for kubernetes clusters', function(done) { |
| 92 | + const cache = createErrorCache(); |
| 93 | + aksDiagnosticLogsEnabled.run(cache, {}, (err, results) => { |
| 94 | + expect(results.length).to.equal(1); |
| 95 | + expect(results[0].status).to.equal(3); |
| 96 | + expect(results[0].message).to.include('Unable to query for Kubernetes clusters: '); |
| 97 | + expect(results[0].region).to.equal('eastus'); |
| 98 | + done(); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should give unknown result if unable to query for diagnostic settings', function(done) { |
| 103 | + const cache = createCache([clusters[0]], null); |
| 104 | + aksDiagnosticLogsEnabled.run(cache, {}, (err, results) => { |
| 105 | + expect(results.length).to.equal(1); |
| 106 | + expect(results[0].status).to.equal(3); |
| 107 | + expect(results[0].message).to.include('Unable to query for Kubernetes cluster diagnostic settings'); |
| 108 | + expect(results[0].region).to.equal('eastus'); |
| 109 | + done(); |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should give passing result if diagnostic logs enabled', function(done) { |
| 114 | + const cache = createCache([clusters[0]], [diagnosticSettings[0]]); |
| 115 | + aksDiagnosticLogsEnabled.run(cache, {}, (err, results) => { |
| 116 | + expect(results.length).to.equal(1); |
| 117 | + expect(results[0].status).to.equal(0); |
| 118 | + expect(results[0].message).to.include('AKS cluster has diagnostic logs enabled'); |
| 119 | + expect(results[0].region).to.equal('eastus'); |
| 120 | + done(); |
| 121 | + }); |
| 122 | + }); |
| 123 | + |
| 124 | + it('should give failing result if diagnostic logs not enabled', function(done) { |
| 125 | + const cache = createCache([clusters[0]], [[]]); |
| 126 | + aksDiagnosticLogsEnabled.run(cache, {}, (err, results) => { |
| 127 | + expect(results.length).to.equal(1); |
| 128 | + expect(results[0].status).to.equal(2); |
| 129 | + expect(results[0].message).to.include('AKS cluster does not have diagnostic logs enabled'); |
| 130 | + expect(results[0].region).to.equal('eastus'); |
| 131 | + done(); |
| 132 | + }); |
| 133 | + }); |
| 134 | + }); |
| 135 | +}); |
0 commit comments