func TestStore(t *testing.T) { storage, backing, ecli := newStorage(t) initialObject(ecli) if _, err := storage.Allocate(2); err != nil { t.Fatal(err) } ok, err := backing.Allocate(2) if err != nil { t.Fatal(err) } if ok { t.Fatal("Expected backing allocation to fail") } if ok, err := storage.Allocate(2); ok || err != nil { t.Fatal("Expected allocation to fail") } obj := ecli.Data[key()] if obj.R == nil || obj.R.Node == nil { t.Fatalf("%s is empty: %#v", key(), obj) } t.Logf("data: %#v", obj.R.Node) other := allocator.NewAllocationMap(100, "rangeSpecValue") allocation := &api.RangeAllocation{} if err := storage.storage.Get(key(), allocation, false); err != nil { t.Fatal(err) } if allocation.ResourceVersion != "1" { t.Fatalf("%#v", allocation) } if allocation.Range != "rangeSpecValue" { t.Errorf("unexpected stored Range: %s", allocation.Range) } if err := other.Restore("rangeSpecValue", allocation.Data); err != nil { t.Fatal(err) } if !other.Has(2) { t.Fatalf("could not restore allocated IP: %#v", other) } other = allocator.NewAllocationMap(100, "rangeSpecValue") otherStorage := NewEtcd(other, "/ranges/serviceips", "serviceipallocation", storage.storage) if ok, err := otherStorage.Allocate(2); ok || err != nil { t.Fatal(err) } }
func TestErrors(t *testing.T) { server, storage, _, _ := newStorage(t) defer server.Terminate(t) if err := storage.Allocate(net.ParseIP("192.168.0.0")); err != ipallocator.ErrNotInRange { t.Fatal(err) } }
func TestEmpty(t *testing.T) { server, storage, _, _ := newStorage(t) defer server.Terminate(t) if err := storage.Allocate(net.ParseIP("192.168.1.2")); !strings.Contains(err.Error(), "cannot allocate resources of type serviceipallocation at this time") { t.Fatal(err) } }
func TestEmpty(t *testing.T) { storage, _, ecli := newStorage(t) ecli.ExpectNotFoundGet(key()) if err := storage.Allocate(net.ParseIP("192.168.1.2")); !strings.Contains(err.Error(), "cannot allocate resources of type serviceipallocation at this time") { t.Fatal(err) } }
func TestErrors(t *testing.T) { _, storage, _, _, destroyFunc := newStorage(t) defer destroyFunc() if err := storage.Allocate(net.ParseIP("192.168.0.0")); err != ipallocator.ErrNotInRange { t.Fatal(err) } }
func TestStore(t *testing.T) { server, storage, backing, si := newStorage(t) defer server.Terminate(t) if err := si.Set(context.TODO(), key(), validNewRangeAllocation(), nil, 0); err != nil { t.Fatalf("unexpected error: %v", err) } if err := storage.Allocate(net.ParseIP("192.168.1.2")); err != nil { t.Fatal(err) } ok, err := backing.Allocate(1) if err != nil { t.Fatal(err) } if ok { t.Fatal("Expected allocation to fail") } if err := storage.Allocate(net.ParseIP("192.168.1.2")); err != ipallocator.ErrAllocated { t.Fatal(err) } }
func TestStore(t *testing.T) { storage, r, ecli := newStorage(t) initialObject(ecli) if err := storage.Allocate(net.ParseIP("192.168.1.2")); err != nil { t.Fatal(err) } ok, err := r.Allocate(1) if err != nil { t.Fatal(err) } if ok { t.Fatal("Expected allocation to fail") } if err := storage.Allocate(net.ParseIP("192.168.1.2")); err != ipallocator.ErrAllocated { t.Fatal(err) } obj := ecli.Data[key()] if obj.R == nil || obj.R.Node == nil { t.Fatalf("%s is empty: %#v", key(), obj) } t.Logf("data: %#v", obj.R.Node) }