|
1 | 1 | package nginx
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "reflect" |
4 | 5 | "testing"
|
5 | 6 | )
|
6 | 7 |
|
@@ -61,3 +62,86 @@ func TestParseStickyServiceInvalidFormat(t *testing.T) {
|
61 | 62 | t.Errorf("parseStickyService(%s) should return error, got nil", stickyService)
|
62 | 63 | }
|
63 | 64 | }
|
| 65 | + |
| 66 | +func TestFilterMasterAnnotations(t *testing.T) { |
| 67 | + masterAnnotations := map[string]string{ |
| 68 | + "nginx.org/rewrites": "serviceName=service1 rewrite=rewrite1", |
| 69 | + "nginx.org/ssl-services": "service1", |
| 70 | + "nginx.org/hsts": "True", |
| 71 | + "nginx.org/hsts-max-age": "2700000", |
| 72 | + "nginx.org/hsts-include-subdomains": "True", |
| 73 | + } |
| 74 | + removedAnnotations := filterMasterAnnotations(masterAnnotations) |
| 75 | + |
| 76 | + expectedfilteredMasterAnnotations := map[string]string{ |
| 77 | + "nginx.org/hsts": "True", |
| 78 | + "nginx.org/hsts-max-age": "2700000", |
| 79 | + "nginx.org/hsts-include-subdomains": "True", |
| 80 | + } |
| 81 | + expectedRemovedAnnotations := []string{ |
| 82 | + "nginx.org/rewrites", |
| 83 | + "nginx.org/ssl-services", |
| 84 | + } |
| 85 | + |
| 86 | + if !reflect.DeepEqual(expectedfilteredMasterAnnotations, masterAnnotations) { |
| 87 | + t.Errorf("filterMasterAnnotations returned %v, but expected %v", masterAnnotations, expectedfilteredMasterAnnotations) |
| 88 | + } |
| 89 | + if !reflect.DeepEqual(expectedRemovedAnnotations, removedAnnotations) { |
| 90 | + t.Errorf("filterMasterAnnotations returned %v, but expected %v", removedAnnotations, expectedRemovedAnnotations) |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +func TestFilterMinionAnnotations(t *testing.T) { |
| 95 | + minionAnnotations := map[string]string{ |
| 96 | + "nginx.org/rewrites": "serviceName=service1 rewrite=rewrite1", |
| 97 | + "nginx.org/ssl-services": "service1", |
| 98 | + "nginx.org/hsts": "True", |
| 99 | + "nginx.org/hsts-max-age": "2700000", |
| 100 | + "nginx.org/hsts-include-subdomains": "True", |
| 101 | + } |
| 102 | + removedAnnotations := filterMinionAnnotations(minionAnnotations) |
| 103 | + |
| 104 | + expectedfilteredMinionAnnotations := map[string]string{ |
| 105 | + "nginx.org/rewrites": "serviceName=service1 rewrite=rewrite1", |
| 106 | + "nginx.org/ssl-services": "service1", |
| 107 | + } |
| 108 | + expectedRemovedAnnotations := []string{ |
| 109 | + "nginx.org/hsts", |
| 110 | + "nginx.org/hsts-max-age", |
| 111 | + "nginx.org/hsts-include-subdomains", |
| 112 | + } |
| 113 | + |
| 114 | + if !reflect.DeepEqual(expectedfilteredMinionAnnotations, minionAnnotations) { |
| 115 | + t.Errorf("filterMinionAnnotations returned %v, but expected %v", minionAnnotations, expectedfilteredMinionAnnotations) |
| 116 | + } |
| 117 | + if !reflect.DeepEqual(expectedRemovedAnnotations, removedAnnotations) { |
| 118 | + t.Errorf("filterMinionAnnotations returned %v, but expected %v", removedAnnotations, expectedRemovedAnnotations) |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +func TestMergeMasterAnnotationsIntoMinion(t *testing.T) { |
| 123 | + masterAnnotations := map[string]string{ |
| 124 | + "nginx.org/proxy-buffering": "True", |
| 125 | + "nginx.org/proxy-buffers": "2", |
| 126 | + "nginx.org/proxy-buffer-size": "8k", |
| 127 | + "nginx.org/hsts": "True", |
| 128 | + "nginx.org/hsts-max-age": "2700000", |
| 129 | + "nginx.org/proxy-connect-timeout": "50s", |
| 130 | + } |
| 131 | + minionAnnotations := map[string]string{ |
| 132 | + "nginx.org/client-max-body-size": "2m", |
| 133 | + "nginx.org/proxy-connect-timeout": "20s", |
| 134 | + } |
| 135 | + mergeMasterAnnotationsIntoMinion(minionAnnotations, masterAnnotations) |
| 136 | + |
| 137 | + expectedMergedAnnotations := map[string]string{ |
| 138 | + "nginx.org/proxy-buffering": "True", |
| 139 | + "nginx.org/proxy-buffers": "2", |
| 140 | + "nginx.org/proxy-buffer-size": "8k", |
| 141 | + "nginx.org/client-max-body-size": "2m", |
| 142 | + "nginx.org/proxy-connect-timeout": "20s", |
| 143 | + } |
| 144 | + if !reflect.DeepEqual(expectedMergedAnnotations, minionAnnotations) { |
| 145 | + t.Errorf("mergeMasterAnnotationsIntoMinion returned %v, but expected %v", minionAnnotations, expectedMergedAnnotations) |
| 146 | + } |
| 147 | +} |
0 commit comments