terraform/helper/shadow/keyed_value_test.go

52 lines
774 B
Go
Raw Normal View History

2016-10-01 03:48:53 +02:00
package shadow
import (
"testing"
"time"
)
func TestKeyedValue(t *testing.T) {
var v KeyedValue
// Start trying to get the value
valueCh := make(chan interface{})
go func() {
valueCh <- v.Value("foo")
}()
// We should not get the value
select {
case <-valueCh:
t.Fatal("shouldn't receive value")
case <-time.After(10 * time.Millisecond):
}
// Set the value
v.SetValue("foo", 42)
val := <-valueCh
// Verify
if val != 42 {
t.Fatalf("bad: %#v", val)
}
// We should get the next value
val = v.Value("foo")
if val != 42 {
t.Fatalf("bad: %#v", val)
}
}
func TestKeyedValue_setFirst(t *testing.T) {
var v KeyedValue
// Set the value
v.SetValue("foo", 42)
val := v.Value("foo")
// Verify
if val != 42 {
t.Fatalf("bad: %#v", val)
}
}