Newer
Older
/*
* Copyright 2015 Manish R Jain <manishrjain@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uid
import (
"io/ioutil"
"os"
"testing"
"github.com/manishrjain/dgraph/posting"
"github.com/manishrjain/dgraph/store"
)
func NewStore(t *testing.T) string {
path, err := ioutil.TempDir("", "storetest_")
if err != nil {
t.Error(err)
t.Fail()
return ""
}
return path
}
func TestGetOrAssign(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel)
pdir := NewStore(t)
defer os.RemoveAll(pdir)
ps := new(store.Store)
ps.Init(pdir)
mdir := NewStore(t)
defer os.RemoveAll(mdir)
ms := new(store.Store)
ms.Init(mdir)
var u1, u2 uint64
{
uid, err := GetOrAssign("externalid0")
if err != nil {
t.Error(err)
}
u1 = uid
}
{
uid, err := GetOrAssign("externalid1")
if err != nil {
t.Error(err)
}
u2 = uid
}
if u1 == u2 {
t.Error("Uid1 and Uid2 shouldn't be the same")
}
{
uid, err := GetOrAssign("externalid0")
if err != nil {
t.Error(err)
}
if u1 != uid {
t.Error("Uid should be the same.")
}
}
{
xid, err := ExternalId(u1)
if err != nil {
t.Error(err)
}
if xid != "externalid0" {
t.Errorf("Expected externalid0. Found: [%q]", xid)
}
}
xid, err := ExternalId(u2)
if err != nil {
t.Error(err)
}
if xid != "externalid1" {
t.Errorf("Expected externalid1. Found: [%q]", xid)