| 71 | } |
| 72 | |
| 73 | func TestNewSource(t *testing.T) { |
| 74 | certsource := func(typ string) config.CertSource { |
| 75 | return config.CertSource{ |
| 76 | Type: typ, |
| 77 | Name: "name", |
| 78 | CertPath: "cert", |
| 79 | KeyPath: "key", |
| 80 | ClientCAPath: "clientca", |
| 81 | CAUpgradeCN: "upgcn", |
| 82 | Refresh: 3 * time.Second, |
| 83 | Header: http.Header{"A": []string{"b"}}, |
| 84 | } |
| 85 | } |
| 86 | tests := []struct { |
| 87 | desc string |
| 88 | cfg config.CertSource |
| 89 | src Source |
| 90 | err string |
| 91 | }{ |
| 92 | { |
| 93 | desc: "invalid", |
| 94 | cfg: config.CertSource{ |
| 95 | Type: "invalid", |
| 96 | }, |
| 97 | src: nil, |
| 98 | err: `invalid certificate source "invalid"`, |
| 99 | }, |
| 100 | { |
| 101 | desc: "file", |
| 102 | cfg: certsource("file"), |
| 103 | src: FileSource{ |
| 104 | CertFile: "cert", |
| 105 | KeyFile: "key", |
| 106 | ClientAuthFile: "clientca", |
| 107 | CAUpgradeCN: "upgcn", |
| 108 | }, |
| 109 | }, |
| 110 | { |
| 111 | desc: "path", |
| 112 | cfg: certsource("path"), |
| 113 | src: PathSource{ |
| 114 | CertPath: "cert", |
| 115 | ClientCAPath: "clientca", |
| 116 | CAUpgradeCN: "upgcn", |
| 117 | Refresh: 3 * time.Second, |
| 118 | }, |
| 119 | }, |
| 120 | { |
| 121 | desc: "http", |
| 122 | cfg: certsource("http"), |
| 123 | src: HTTPSource{ |
| 124 | CertURL: "cert", |
| 125 | ClientCAURL: "clientca", |
| 126 | CAUpgradeCN: "upgcn", |
| 127 | Refresh: 3 * time.Second, |
| 128 | }, |
| 129 | }, |
| 130 | { |