(t *testing.T)
| 124 | } |
| 125 | |
| 126 | func TestNewMasterKeyFromURI(t *testing.T) { |
| 127 | tests := []struct { |
| 128 | url string |
| 129 | want *MasterKey |
| 130 | wantErr bool |
| 131 | }{ |
| 132 | { |
| 133 | url: "https://vault.example.com:8200/v1/transit/keys/keyName", |
| 134 | want: &MasterKey{ |
| 135 | VaultAddress: "https://vault.example.com:8200", |
| 136 | EnginePath: "transit", |
| 137 | KeyName: "keyName", |
| 138 | }, |
| 139 | }, |
| 140 | { |
| 141 | url: "https://vault.me.com/v1/super42/bestmarket/keys/slig", |
| 142 | want: &MasterKey{ |
| 143 | VaultAddress: "https://vault.me.com", |
| 144 | EnginePath: "super42/bestmarket", |
| 145 | KeyName: "slig", |
| 146 | }, |
| 147 | }, |
| 148 | { |
| 149 | url: "http://127.0.0.1:12121/v1/transit/keys/dev", |
| 150 | want: &MasterKey{ |
| 151 | VaultAddress: "http://127.0.0.1:12121", |
| 152 | EnginePath: "transit", |
| 153 | KeyName: "dev", |
| 154 | }, |
| 155 | }, |
| 156 | { |
| 157 | url: "vault.me/keys/dev/mykey", |
| 158 | want: nil, |
| 159 | wantErr: true, |
| 160 | }, |
| 161 | { |
| 162 | url: "http://127.0.0.1:12121/v1/keys/dev", |
| 163 | want: nil, |
| 164 | wantErr: true, |
| 165 | }, |
| 166 | { |
| 167 | url: "tcp://127.0.0.1:12121/v1/keys/dev", |
| 168 | want: nil, |
| 169 | wantErr: true, |
| 170 | }, |
| 171 | } |
| 172 | for _, tt := range tests { |
| 173 | t.Run(tt.url, func(t *testing.T) { |
| 174 | got, err := NewMasterKeyFromURI(tt.url) |
| 175 | if tt.wantErr { |
| 176 | assert.Error(t, err) |
| 177 | } else { |
| 178 | assert.NoError(t, err) |
| 179 | } |
| 180 | if tt.want != nil && got != nil { |
| 181 | tt.want.CreationDate = got.CreationDate |
| 182 | } |
| 183 | assert.Equal(t, tt.want, got) |
nothing calls this directly
no test coverage detected