|
| 1 | +package heroku |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestIsFeatureSupported(t *testing.T) { |
| 8 | + testCases := []struct { |
| 9 | + name string |
| 10 | + generation string |
| 11 | + resourceType string |
| 12 | + feature string |
| 13 | + expected bool |
| 14 | + }{ |
| 15 | + // Cedar generation tests - all space features supported |
| 16 | + { |
| 17 | + name: "Cedar space private should be supported", |
| 18 | + generation: "cedar", |
| 19 | + resourceType: "space", |
| 20 | + feature: "private", |
| 21 | + expected: true, |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "Cedar space shield should be supported", |
| 25 | + generation: "cedar", |
| 26 | + resourceType: "space", |
| 27 | + feature: "shield", |
| 28 | + expected: true, |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "Cedar space trusted_ip_ranges should be supported", |
| 32 | + generation: "cedar", |
| 33 | + resourceType: "space", |
| 34 | + feature: "trusted_ip_ranges", |
| 35 | + expected: true, |
| 36 | + }, |
| 37 | + |
| 38 | + // Fir generation tests - private supported, shield and others unsupported |
| 39 | + { |
| 40 | + name: "Fir space private should be supported", |
| 41 | + generation: "fir", |
| 42 | + resourceType: "space", |
| 43 | + feature: "private", |
| 44 | + expected: true, |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "Fir space shield should be unsupported", |
| 48 | + generation: "fir", |
| 49 | + resourceType: "space", |
| 50 | + feature: "shield", |
| 51 | + expected: false, |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "Fir space trusted_ip_ranges should be unsupported", |
| 55 | + generation: "fir", |
| 56 | + resourceType: "space", |
| 57 | + feature: "trusted_ip_ranges", |
| 58 | + expected: false, |
| 59 | + }, |
| 60 | + |
| 61 | + // Unsupported feature tests (features not in matrix) |
| 62 | + { |
| 63 | + name: "Cedar space unknown_feature should be unsupported (not in matrix)", |
| 64 | + generation: "cedar", |
| 65 | + resourceType: "space", |
| 66 | + feature: "unknown_feature", |
| 67 | + expected: false, |
| 68 | + }, |
| 69 | + { |
| 70 | + name: "Fir space unknown_feature should be unsupported (not in matrix)", |
| 71 | + generation: "fir", |
| 72 | + resourceType: "space", |
| 73 | + feature: "unknown_feature", |
| 74 | + expected: false, |
| 75 | + }, |
| 76 | + |
| 77 | + // Unknown resource type tests |
| 78 | + { |
| 79 | + name: "Cedar app features should be unsupported (not implemented yet)", |
| 80 | + generation: "cedar", |
| 81 | + resourceType: "app", |
| 82 | + feature: "some_feature", |
| 83 | + expected: false, |
| 84 | + }, |
| 85 | + { |
| 86 | + name: "Fir build features should be unsupported (not implemented yet)", |
| 87 | + generation: "fir", |
| 88 | + resourceType: "build", |
| 89 | + feature: "some_feature", |
| 90 | + expected: false, |
| 91 | + }, |
| 92 | + |
| 93 | + // Invalid generation tests |
| 94 | + { |
| 95 | + name: "Invalid generation should be unsupported", |
| 96 | + generation: "invalid", |
| 97 | + resourceType: "space", |
| 98 | + feature: "shield", |
| 99 | + expected: false, |
| 100 | + }, |
| 101 | + { |
| 102 | + name: "Empty generation should be unsupported", |
| 103 | + generation: "", |
| 104 | + resourceType: "space", |
| 105 | + feature: "shield", |
| 106 | + expected: false, |
| 107 | + }, |
| 108 | + |
| 109 | + // Edge case tests |
| 110 | + { |
| 111 | + name: "Empty resource type should be unsupported", |
| 112 | + generation: "cedar", |
| 113 | + resourceType: "", |
| 114 | + feature: "shield", |
| 115 | + expected: false, |
| 116 | + }, |
| 117 | + { |
| 118 | + name: "Empty feature should be unsupported", |
| 119 | + generation: "cedar", |
| 120 | + resourceType: "space", |
| 121 | + feature: "", |
| 122 | + expected: false, |
| 123 | + }, |
| 124 | + } |
| 125 | + |
| 126 | + for _, tc := range testCases { |
| 127 | + t.Run(tc.name, func(t *testing.T) { |
| 128 | + result := IsFeatureSupported(tc.generation, tc.resourceType, tc.feature) |
| 129 | + if result != tc.expected { |
| 130 | + t.Errorf("IsFeatureSupported(%q, %q, %q) = %v, expected %v", |
| 131 | + tc.generation, tc.resourceType, tc.feature, result, tc.expected) |
| 132 | + } |
| 133 | + }) |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +// TestFeatureMatrixConsistency ensures the feature matrix is internally consistent |
| 138 | +func TestFeatureMatrixConsistency(t *testing.T) { |
| 139 | + // Verify that all generations have at least one resource |
| 140 | + for generation, resources := range featureMatrix { |
| 141 | + if len(resources) == 0 { |
| 142 | + t.Errorf("Generation %s has no resources defined", generation) |
| 143 | + } |
| 144 | + |
| 145 | + // Verify that all resources have at least one feature |
| 146 | + for resourceType, features := range resources { |
| 147 | + if len(features) == 0 { |
| 148 | + t.Errorf("Generation %s, resource %s has no features defined", generation, resourceType) |
| 149 | + } |
| 150 | + |
| 151 | + // Verify that all features are properly set (no nil values) |
| 152 | + for feature, supported := range features { |
| 153 | + if feature == "" { |
| 154 | + t.Errorf("Generation %s, resource %s has empty feature name", generation, resourceType) |
| 155 | + } |
| 156 | + // supported is bool, so just verify it's not accidentally unset in a way that would matter |
| 157 | + _ = supported // This is intentional - we're just ensuring the value exists |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + // Verify minimum required features exist for Task 1 |
| 163 | + // Both generations support private spaces |
| 164 | + if !IsFeatureSupported("cedar", "space", "private") { |
| 165 | + t.Error("Cedar space private must be supported") |
| 166 | + } |
| 167 | + if !IsFeatureSupported("fir", "space", "private") { |
| 168 | + t.Error("Fir space private must be supported") |
| 169 | + } |
| 170 | + |
| 171 | + // Only cedar supports shield spaces |
| 172 | + if !IsFeatureSupported("cedar", "space", "shield") { |
| 173 | + t.Error("Cedar space shield must be supported") |
| 174 | + } |
| 175 | + if IsFeatureSupported("fir", "space", "shield") { |
| 176 | + t.Error("Fir space shield must be unsupported") |
| 177 | + } |
| 178 | +} |
0 commit comments