本文整理汇总了Golang中github.com/pborman/uuid.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDeleteRefs
// Create floating-ip with 2 vmi references, delete it and verify that
// the back_refs are updated as expected.
func TestDeleteRefs(t *testing.T) {
db := NewInMemDatabase()
vmi1 := new(types.VirtualMachineInterface)
vmi1.SetUuid(uuid.New())
vmi1.SetName("port1")
assert.NoError(t, db.Put(vmi1, nil, GetReferenceList(vmi1)))
vmi2 := new(types.VirtualMachineInterface)
vmi2.SetUuid(uuid.New())
vmi2.SetName("port2")
assert.NoError(t, db.Put(vmi2, nil, GetReferenceList(vmi2)))
fip := new(types.FloatingIp)
fip.SetUuid(uuid.New())
fip.SetName("fip")
fip.AddVirtualMachineInterface(vmi1)
fip.AddVirtualMachineInterface(vmi2)
assert.NoError(t, db.Put(fip, nil, GetReferenceList(fip)))
assert.Error(t, db.Delete(vmi1))
result, err := db.GetBackReferences(parseUID(vmi2.GetUuid()), "floating_ip")
assert.NoError(t, err)
assert.Len(t, result, 1)
assert.NoError(t, db.Delete(fip))
result, err = db.GetBackReferences(parseUID(vmi2.GetUuid()), "floating_ip")
assert.NoError(t, err)
assert.Len(t, result, 0)
assert.NoError(t, db.Delete(vmi1))
assert.NoError(t, db.Delete(vmi2))
}
示例2: TestState_LoadCluster
func TestState_LoadCluster(t *testing.T) {
t.Parallel()
testPrefix := "TestState_LoadClusterState"
testutil.ResetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
state, err := NewStateEtcdWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatalf("Could not create state", err)
}
instanceID := structs.ClusterID(uuid.New())
planID := uuid.New()
clusterState := structs.ClusterState{
InstanceID: instanceID,
OrganizationGUID: "OrganizationGUID",
PlanID: planID,
ServiceID: "ServiceID",
SpaceGUID: "SpaceGUID",
}
err = state.SaveCluster(clusterState)
if err != nil {
t.Fatalf("SaveCluster failed %s", err)
}
loadedState, err := state.LoadCluster(instanceID)
if !reflect.DeepEqual(clusterState, loadedState) {
t.Fatalf("Failed to load ClusterState")
}
}
示例3: TestUpdateOne
func TestUpdateOne(t *testing.T) {
db := NewInMemDatabase()
instance := new(types.VirtualMachine)
instance.SetUuid(uuid.New())
instance.SetName("instance")
assert.NoError(t, db.Put(instance, nil, UIDList{}))
vmi1 := new(types.VirtualMachineInterface)
vmi1.SetUuid(uuid.New())
vmi1.SetName("port1")
assert.NoError(t, db.Put(vmi1, nil, GetReferenceList(vmi1)))
vmi1.AddVirtualMachine(instance)
assert.NoError(t, db.Update(vmi1, GetReferenceList(vmi1)))
result, err := db.GetBackReferences(parseUID(instance.GetUuid()), "virtual_machine_interface")
assert.NoError(t, err)
assert.Contains(t, result, parseUID(vmi1.GetUuid()))
vmi1.ClearVirtualMachine()
assert.NoError(t, db.Update(vmi1, GetReferenceList(vmi1)))
result, err = db.GetBackReferences(parseUID(instance.GetUuid()), "virtual_machine_interface")
assert.NoError(t, err)
assert.Len(t, result, 0)
}
示例4: TestStoreFailsOnInvalidUserData
func TestStoreFailsOnInvalidUserData(t *testing.T) {
client := &osin.DefaultClient{Id: "3", Secret: "secret", RedirectUri: "http://localhost/", UserData: ""}
authorize := &osin.AuthorizeData{
Client: client,
Code: uuid.New(),
ExpiresIn: int32(60),
Scope: "scope",
RedirectUri: "http://localhost/",
State: "state",
CreatedAt: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
UserData: struct{ foo string }{"bar"},
}
access := &osin.AccessData{
Client: client,
AuthorizeData: authorize,
AccessData: nil,
AccessToken: uuid.New(),
RefreshToken: uuid.New(),
ExpiresIn: int32(60),
Scope: "scope",
RedirectUri: "https://localhost/",
CreatedAt: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
UserData: struct{ foo string }{"bar"},
}
assert.NotNil(t, store.SaveAuthorize(authorize))
assert.NotNil(t, store.SaveAccess(access))
}
示例5: TestToolDoesNotExist
func TestToolDoesNotExist(t *testing.T) {
// Build the Queue with the SimpleTool timer
q := Queue{authToken: "ResourceTest"}
// Add the tool
st := new(SimpleTimerTooler)
st.SetUUID(uuid.New())
q.tools = append(q.tools, st)
// Create the RPC server and bind the Queue
listen := startRPCOnce("tcp", addr, &q)
defer listen.Close()
// Connect to the RPC server
client, err := rpc.Dial("tcp", addr)
if err != nil {
t.Fatal("Error dailing RPC server.", err)
}
defer client.Close()
// Setup the Job information to start the service
params := map[string]string{"timer": "1"}
j := common.NewJob(uuid.New(), "Testing Job", "GoTestSuite", params)
// Create RPC call for starting a job
startJob := common.RPCCall{Auth: "ResourceTest", Job: j}
// Make call and expect an error of bad job
err = client.Call("Queue.AddTask", startJob, &j)
if err == nil || err.Error() != ERROR_NO_TOOL {
t.Fatal("No tool error was not returned.", err)
}
}
示例6: tryCrypto
func tryCrypto() {
pwd := "pwd"
hash, err := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.DefaultCost)
if err != nil {
P("bcrypt err: ", err)
}
P("first, pwd and hansh: \n", pwd, string(hash), len(string(hash)))
hash2, _ := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.DefaultCost)
P("second, pwd and hash: \n", pwd, string(hash2), len(string(hash2)))
P("check pwd..")
P("check hash1: ")
err = bcrypt.CompareHashAndPassword(hash, []byte(pwd))
P(err == nil)
err = bcrypt.CompareHashAndPassword(hash, []byte("pwds"))
P(err == nil)
P("check has2:")
P("hash1 != hash2: ", string(hash) != string(hash2))
err = bcrypt.CompareHashAndPassword(hash2, []byte(pwd))
P(err == nil)
u := uuid.New()
P("uuid: ", u, len(u), len(uuid.New()), len(uuid.New()))
unix := time.Now().Unix()
unixStr := fmt.Sprintf("%d", unix)
P("time: ", unix, len(unixStr))
}
示例7: TestUpdateUsername
func TestUpdateUsername(t *testing.T) {
id := uuid.New()
_, _ = store.Create(account.CreateAccountRequest{
ID: id,
Username: uuid.New(),
Password: "secret",
})
_, err := store.UpdateUsername(id, account.UpdateUsernameRequest{
Username: uuid.New(),
Password: "wrong secret",
})
assert.NotNil(t, err)
r, err := store.UpdateUsername(id, account.UpdateUsernameRequest{
Username: "[email protected]",
Password: "secret",
})
assert.Nil(t, err)
assert.Equal(t, "[email protected]", r.GetUsername())
// Did it persist?
r, err = store.Get(id)
assert.Nil(t, err)
assert.Equal(t, "[email protected]", r.GetUsername())
}
示例8: TestRefreshOperations
func TestRefreshOperations(t *testing.T) {
client := &osin.DefaultClient{Id: "4", Secret: "secret", RedirectUri: "http://localhost/", UserData: ""}
type test struct {
access *osin.AccessData
}
for k, c := range []*test{
{
access: &osin.AccessData{
Client: client,
AuthorizeData: &osin.AuthorizeData{
Client: client,
Code: uuid.New(),
ExpiresIn: int32(60),
Scope: "scope",
RedirectUri: "http://localhost/",
State: "state",
CreatedAt: time.Now().Round(time.Second),
UserData: userDataMock,
},
AccessData: nil,
AccessToken: uuid.New(),
RefreshToken: uuid.New(),
ExpiresIn: int32(60),
Scope: "scope",
RedirectUri: "https://localhost/",
CreatedAt: time.Now().Round(time.Second),
UserData: userDataMock,
},
},
} {
createClient(t, store, client)
require.Nil(t, store.SaveAuthorize(c.access.AuthorizeData), "Case %d", k)
require.Nil(t, store.SaveAccess(c.access), "Case %d", k)
result, err := store.LoadRefresh(c.access.RefreshToken)
require.Nil(t, err)
require.Equal(t, c.access.CreatedAt.Unix(), result.CreatedAt.Unix())
require.Equal(t, c.access.AuthorizeData.CreatedAt.Unix(), result.AuthorizeData.CreatedAt.Unix())
c.access.CreatedAt = result.CreatedAt
c.access.AuthorizeData.CreatedAt = result.AuthorizeData.CreatedAt
require.Equal(t, c.access, result, "Case %d", k)
require.Nil(t, store.RemoveRefresh(c.access.RefreshToken))
_, err = store.LoadRefresh(c.access.RefreshToken)
require.NotNil(t, err, "Case %d", k)
require.Nil(t, store.RemoveAccess(c.access.AccessToken), "Case %d", k)
require.Nil(t, store.SaveAccess(c.access), "Case %d", k)
_, err = store.LoadRefresh(c.access.RefreshToken)
require.Nil(t, err, "Case %d", k)
require.Nil(t, store.RemoveAccess(c.access.AccessToken), "Case %d", k)
_, err = store.LoadRefresh(c.access.RefreshToken)
require.NotNil(t, err, "Case %d", k)
}
removeClient(t, store, client)
}
示例9: TestCreateAndGetCases
func TestCreateAndGetCases(t *testing.T) {
var stateDataSet = map[string]storage.StateData{
"valid": {
ID: uuid.New(),
ClientID: uuid.New(),
RedirectURL: "http://localhost/",
Scope: "scope",
State: "state",
Type: "code",
Provider: "facebook",
ExpiresAt: time.Now().Add(time.Hour),
},
"invalid": {},
}
for k, c := range []struct {
sd storage.StateData
passCreate bool
passGet bool
}{
{stateDataSet["valid"], true, true},
} {
assert.Equal(t, c.passCreate, store.SaveStateData(&c.sd) == nil, "Case %d", k)
if !c.passCreate {
continue
}
result, err := store.GetStateData(c.sd.ID)
assert.Nil(t, err, "Case %d", k)
assert.Equal(t, c.sd.IsExpired(), result.IsExpired(), "Case %d", k)
c.sd.ExpiresAt = result.ExpiresAt
assert.Equal(t, &c.sd, result, "Case %d", k)
}
}
示例10: TestState_ClusterExists
func TestState_ClusterExists(t *testing.T) {
t.Parallel()
testPrefix := "TestState_ClusterExists"
testutil.ResetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
state, err := NewStateEtcdWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatalf("Could not create state", err)
}
clusterID := structs.ClusterID(uuid.New())
planID := uuid.New()
clusterState := structs.ClusterState{
InstanceID: clusterID,
OrganizationGUID: "OrganizationGUID",
PlanID: planID,
ServiceID: "ServiceID",
SpaceGUID: "SpaceGUID",
}
err = state.SaveCluster(clusterState)
if err != nil {
t.Fatalf("SaveCluster failed %s", err)
}
if !state.ClusterExists(clusterID) {
t.Fatalf("Cluster %s should exist", clusterID)
}
if state.ClusterExists("fakeID") {
t.Fatalf("Cluster %s should not exist", "fakeID")
}
}
示例11: TestValidate
func (s *RequestTestSuite) TestValidate() {
rh, _ := url.ParseRequestURI("unix:///tmp")
tests := []struct {
description string
id string
task string
responseHook *url.URL
expectedErr bool
}{
{"missing ID", "", "foo", rh, true},
{"missing Task", uuid.New(), "", rh, true},
{"missing ResponseHook", uuid.New(), "foo", nil, true},
{"valid", uuid.New(), "foo", rh, false},
}
for _, test := range tests {
msg := testMsgFunc(test.description)
req := &acomm.Request{
ID: test.id,
Task: test.task,
ResponseHook: test.responseHook,
}
if test.expectedErr {
s.Error(req.Validate(), msg("should not be valid"))
} else {
s.NoError(req.Validate(), msg("should be valid"))
}
}
}
示例12: TestUpdatePassword
func TestUpdatePassword(t *testing.T) {
id := uuid.New()
ac, _ := store.Create(account.CreateAccountRequest{
ID: id,
Username: uuid.New(),
Password: "secret",
})
_, err := store.UpdatePassword(id, account.UpdatePasswordRequest{
CurrentPassword: "wrong old secret",
NewPassword: "new secret",
})
assert.NotNil(t, err)
updatedAccount, err := store.UpdatePassword(id, account.UpdatePasswordRequest{
CurrentPassword: "secret",
NewPassword: "new secret",
})
assert.Nil(t, err)
resultAccount, err := store.Get(id)
assert.Nil(t, err)
assert.Equal(t, updatedAccount.GetPassword(), resultAccount.GetPassword())
assert.NotEqual(t, ac.GetPassword(), resultAccount.GetPassword())
}
示例13: TestAcquireExistsWait
func TestAcquireExistsWait(t *testing.T) {
t.Parallel()
key := "lock-TestAcquireExistsWait"
id1 := uuid.New()
id2 := uuid.New()
ttl := uint64(2)
c := newClient(t)
defer cleanup(c, key)
_, err := Acquire(c, key, id1, ttl, false)
if err != nil {
t.Fatal(err)
}
tstart := time.Now().Unix()
_, err = Acquire(c, key, id2, ttl, true)
if err != nil {
t.Fatal(err)
}
tstop := time.Now().Unix()
if uint64(tstop-tstart) < ttl-1 {
t.Fatalf("expected atleast %ds(ttl-1) wait time, got: %d\n", ttl-1, tstop-tstart)
}
resp, err := c.Get(key, false, false)
if err != nil {
t.Fatal(err)
}
if resp.Node.Value != id2 {
t.Fatalf("incorrect data in lock, wanted: %s, got: %s\n", id2, resp.Node.Value)
}
}
示例14: TestTLSGen
func TestTLSGen(t *testing.T) {
priv := filepath.Join(tmpDir, uuid.New())
pub := filepath.Join(tmpDir, uuid.New())
os.Args = []string{"hydra-host", "tls", "generate-dummy-certificate", "-c", priv, "-k", pub, "-u", "localhost", "--sd", "Jan 1 15:04:05 2011", "-d", "8760h0m0s", "--ca", "--rb", "4069", "--ec", "P521"}
assert.Nil(t, NewApp().Run(os.Args))
assertAndRemoveFile(t, priv)
assertAndRemoveFile(t, pub)
}
示例15: TestJWTGen
func TestJWTGen(t *testing.T) {
priv := filepath.Join(tmpDir, uuid.New())
pub := filepath.Join(tmpDir, uuid.New())
os.Args = []string{"hydra-host", "jwt", "generate-keypair", "-s", priv, "-p", pub}
assert.Nil(t, NewApp().Run(os.Args))
assertAndRemoveFile(t, priv)
assertAndRemoveFile(t, pub)
}