mirror of https://github.com/status-im/consul.git
agent: adjust rpc client tests for keyring
This commit is contained in:
parent
fcba072246
commit
f86904ee59
|
@ -315,9 +315,11 @@ func TestRPCClientInstallKey(t *testing.T) {
|
|||
}
|
||||
|
||||
// install key2
|
||||
if _, err := p1.client.InstallKey(key2); err != nil {
|
||||
r, err := p1.client.InstallKey(key2)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
keyringSuccess(t, r)
|
||||
|
||||
// key2 should now be installed
|
||||
keys = listKeys(t, p1.client)
|
||||
|
@ -337,9 +339,11 @@ func TestRPCClientUseKey(t *testing.T) {
|
|||
defer p1.Close()
|
||||
|
||||
// add a second key to the ring
|
||||
if _, err := p1.client.InstallKey(key2); err != nil {
|
||||
r, err := p1.client.InstallKey(key2)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
keyringSuccess(t, r)
|
||||
|
||||
// key2 is installed
|
||||
keys := listKeys(t, p1.client)
|
||||
|
@ -351,19 +355,25 @@ func TestRPCClientUseKey(t *testing.T) {
|
|||
}
|
||||
|
||||
// can't remove key1 yet
|
||||
if _, err := p1.client.RemoveKey(key1); err == nil {
|
||||
t.Fatalf("expected error removing primary key")
|
||||
r, err = p1.client.RemoveKey(key1)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
keyringError(t, r)
|
||||
|
||||
// change primary key
|
||||
if _, err := p1.client.UseKey(key2); err != nil {
|
||||
r, err = p1.client.UseKey(key2)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
keyringSuccess(t, r)
|
||||
|
||||
// can remove key1 now
|
||||
if _, err := p1.client.RemoveKey(key1); err != nil {
|
||||
r, err = p1.client.RemoveKey(key1)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
keyringSuccess(t, r)
|
||||
}
|
||||
|
||||
func TestRPCClientKeyOperation_encryptionDisabled(t *testing.T) {
|
||||
|
@ -371,13 +381,10 @@ func TestRPCClientKeyOperation_encryptionDisabled(t *testing.T) {
|
|||
defer p1.Close()
|
||||
|
||||
r, err := p1.client.ListKeys()
|
||||
if err == nil {
|
||||
t.Fatalf("no error listing keys with encryption disabled")
|
||||
}
|
||||
|
||||
if len(r.Messages) != 1 {
|
||||
t.Fatalf("bad: %#v", r)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
keyringError(t, r)
|
||||
}
|
||||
|
||||
func listKeys(t *testing.T, c *RPCClient) map[string]map[string]int {
|
||||
|
@ -395,3 +402,19 @@ func listKeys(t *testing.T, c *RPCClient) map[string]map[string]int {
|
|||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func keyringError(t *testing.T, r keyResponse) {
|
||||
for _, i := range r.Info {
|
||||
if i.Error == "" {
|
||||
t.Fatalf("no error reported from %s (%s)", i.Datacenter, i.Pool)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func keyringSuccess(t *testing.T, r keyResponse) {
|
||||
for _, i := range r.Info {
|
||||
if i.Error != "" {
|
||||
t.Fatalf("error from %s (%s): %s", i.Datacenter, i.Pool, i.Error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ func testAgentWithConfig(c *agent.Config, t *testing.T) *agentWrapper {
|
|||
|
||||
conf := nextConfig()
|
||||
if c != nil {
|
||||
conf = agent.MergeConfig(conf, c)
|
||||
conf = agent.MergeConfig(c, conf)
|
||||
}
|
||||
|
||||
dir, err := ioutil.TempDir("", "agent")
|
||||
|
|
Loading…
Reference in New Issue