Fixing the test suite.

This commit is contained in:
Bruno Miguel Custodio 2017-09-08 17:46:39 +01:00
parent 038f5eb638
commit 6570948bea
No known key found for this signature in database
GPG Key ID: 84CDD9E18A1A6B2C
2 changed files with 12 additions and 7 deletions

View File

@ -148,7 +148,7 @@ func (c *RemoteClient) getLockInfo() (*state.LockInfo, error) {
}
func (c *RemoteClient) putLockInfo(info *state.LockInfo) error {
c.info.Path = c.Key
c.info.Path = c.etcdMutex.Key()
c.info.Created = time.Now().UTC()
_, err := c.Client.KV.Put(context.TODO(), c.Key+lockInfoSuffix, string(c.info.Marshal()))

View File

@ -3,7 +3,6 @@ package etcd
import (
"context"
"fmt"
"os"
"testing"
"time"
@ -21,7 +20,7 @@ func TestRemoteClient(t *testing.T) {
// Get the backend
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
"endpoints": os.Getenv("TF_ETCDV3_ENDPOINTS"),
"endpoints": etcdv3Endpoints,
"prefix": fmt.Sprintf("%s/%s", keyPrefix, time.Now().String()),
})
@ -42,7 +41,7 @@ func TestEtcdv3_stateLock(t *testing.T) {
// Get the backend
s1, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
"endpoints": os.Getenv("TF_ETCDV3_ENDPOINTS"),
"endpoints": etcdv3Endpoints,
"prefix": key,
}).State(backend.DefaultStateName)
if err != nil {
@ -50,7 +49,7 @@ func TestEtcdv3_stateLock(t *testing.T) {
}
s2, err := backend.TestBackendConfig(t, New(), map[string]interface{}{
"endpoints": os.Getenv("TF_ETCDV3_ENDPOINTS"),
"endpoints": etcdv3Endpoints,
"prefix": key,
}).State(backend.DefaultStateName)
if err != nil {
@ -65,7 +64,7 @@ func TestEtcdv3_destroyLock(t *testing.T) {
// Get the backend
b := backend.TestBackendConfig(t, New(), map[string]interface{}{
"endpoints": os.Getenv("TF_ETCDV3_ENDPOINTS"),
"endpoints": etcdv3Endpoints,
"prefix": fmt.Sprintf("tf-unit/%s", time.Now().String()),
})
@ -87,11 +86,17 @@ func TestEtcdv3_destroyLock(t *testing.T) {
t.Fatal(err)
}
res, err := c.Client.KV.Get(context.TODO(), c.Key)
res, err := c.Client.KV.Get(context.TODO(), c.info.Path)
if err != nil {
t.Fatal(err)
}
if res.Count != 0 {
t.Fatalf("lock key not cleaned up at: %s", string(res.Kvs[0].Key))
}
// Cleanup leftover state.
c.Client.KV.Delete(context.TODO(), c.Key)
if err != nil {
t.Fatal(err)
}
}