本文整理匯總了Golang中github.com/CenturyLinkCloud/clc-sdk/server.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestCreateServer
func TestCreateServer(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Post", "http://localhost/v2/servers/test", mock.Anything, mock.Anything).Return(nil)
service := server.New(client)
server := server.Server{
Name: "server",
CPU: 1,
MemoryGB: 1,
GroupID: "group",
SourceServerID: "UBUNTU",
Type: "standard",
}
s, err := service.Create(server)
ok, id := s.GetStatusID()
assert.Nil(err)
assert.True(s.IsQueued)
assert.Equal(server.Name, s.Server)
assert.True(ok)
assert.NotEmpty(id)
client.AssertExpectations(t)
}
示例2: TestUpdateServer_UpdateCredentials
func TestUpdateServer_UpdateCredentials(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
update := []api.Update{
api.Update{
Op: "set",
Member: "password",
Value: struct {
Current string `json:"current"`
Password string `json:"password"`
}{
"current",
"new",
},
},
}
client.On("Patch", "http://localhost/v2/servers/test/va1testserver01", update, mock.Anything).Return(nil)
service := server.New(client)
name := "va1testserver01"
resp, err := service.Update(name, server.UpdateCredentials("current", "new"))
assert.Nil(err)
assert.Equal("status", resp.Rel)
client.AssertExpectations(t)
}
示例3: TestCreateServer_InvalidServer
func TestCreateServer_InvalidServer(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
service := server.New(client)
s := server.Server{}
_, err := service.Create(s)
assert.NotNil(err)
assert.Equal(err, server.ErrInvalidServer)
}
示例4: TestGetServerByUUID
func TestGetServerByUUID(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Get", "http://localhost/v2/servers/test/5404cf5ece2042dc9f2ac16ab67416bb?uuid=true", mock.Anything).Return(nil)
service := server.New(client)
resp, err := service.Get("5404cf5ece2042dc9f2ac16ab67416bb")
assert.Nil(err)
assert.Equal("va1testserver01", resp.Name)
client.AssertExpectations(t)
}
示例5: TestPowerState_StopMaintenance
func TestPowerState_StopMaintenance(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Post", "http://localhost/v2/operations/test/servers/stopMaintenance", []string{"va1testserver01", "va1testserver02"}, mock.Anything).Return(nil)
service := server.New(client)
resp, err := service.PowerState(server.StopMaintenance, "va1testserver01", "va1testserver02")
assert.Nil(err)
assert.Equal(2, len(resp))
client.AssertExpectations(t)
}
示例6: TestDeleteServer
func TestDeleteServer(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Delete", "http://localhost/v2/servers/test/va1testserver01", mock.Anything).Return(nil)
service := server.New(client)
name := "va1testserver01"
server, err := service.Delete(name)
assert.Nil(err)
assert.Equal(name, server.Server)
client.AssertExpectations(t)
}
示例7: TestGetServer
func TestGetServer(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Get", "http://localhost/v2/servers/test/va1testserver01", mock.Anything).Return(nil)
service := server.New(client)
name := "va1testserver01"
resp, err := service.Get(name)
assert.Nil(err)
assert.Equal(name, resp.Name)
client.AssertExpectations(t)
}
示例8: TestRevertSnapshot
func TestRevertSnapshot(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Post", "http://localhost/v2/servers/test/va1testserver01/snapshots/10/restore", nil, mock.Anything).Return(nil)
service := server.New(client)
server := "va1testserver01"
resp, err := service.RevertSnapshot(server, "10")
assert.Nil(err)
assert.NotEmpty(resp.ID)
client.AssertExpectations(t)
}
示例9: TestGetServerCredentials
func TestGetServerCredentials(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Get", "http://localhost/v2/servers/test/va1testserver01/credentials", mock.Anything).Return(nil)
service := server.New(client)
resp, err := service.GetCredentials("va1testserver01")
assert.Nil(err)
assert.Equal("user", resp.Username)
assert.Equal("pass", resp.Password)
client.AssertExpectations(t)
}
示例10: New
func New(config api.Config) *Client {
c := &Client{
client: api.New(config),
}
c.Server = server.New(c.client)
c.Status = status.New(c.client)
c.AA = aa.New(c.client)
c.Alert = alert.New(c.client)
c.LB = lb.New(c.client)
c.Group = group.New(c.client)
c.DC = dc.New(c.client)
return c
}
示例11: TestArchiveServer
func TestArchiveServer(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Post", "http://localhost/v2/operations/test/servers/archive", mock.Anything, mock.Anything).Return(nil)
service := server.New(client)
serverA := "va1testserver01"
serverB := "va1testserver02"
resp, err := service.Archive(serverA, serverB)
assert.Nil(err)
assert.Equal(2, len(resp))
client.AssertExpectations(t)
}
示例12: TestUpdateServer_UpdateCPU
func TestUpdateServer_UpdateCPU(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
update := []api.Update{api.Update{Op: "set", Member: "cpu", Value: 1}}
client.On("Patch", "http://localhost/v2/servers/test/va1testserver01", update, mock.Anything).Return(nil)
service := server.New(client)
name := "va1testserver01"
resp, err := service.Update(name, server.UpdateCPU(1))
assert.Nil(err)
assert.Equal("status", resp.Rel)
client.AssertExpectations(t)
}
示例13: TestCreateSnapshot
func TestCreateSnapshot(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
snapshot := server.Snapshot{Expiration: 3, Servers: []string{"va1testserver01", "va1testserver02"}}
client.On("Post", "http://localhost/v2/operations/test/servers/createSnapshot", snapshot, mock.Anything).Return(nil)
service := server.New(client)
serverA := "va1testserver01"
serverB := "va1testserver02"
resp, err := service.CreateSnapshot(3, serverA, serverB)
assert.Nil(err)
assert.Equal(2, len(resp))
client.AssertExpectations(t)
}
示例14: TestDeletePublicIP
func TestDeletePublicIP(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
client.On("Delete", mock.Anything, mock.Anything).Return(nil)
service := server.New(client)
addr := "10.0.0.1"
name := "va1testserver01"
resp, err := service.DeletePublicIP(name, addr)
assert.Nil(err)
assert.NotEmpty(resp.ID)
client.AssertExpectations(t)
}
示例15: TestUpdateServer_UpdateGroupAndDescription
func TestUpdateServer_UpdateGroupAndDescription(t *testing.T) {
assert := assert.New(t)
client := NewMockClient()
update := []api.Update{
api.Update{Op: "set", Member: "groupId", Value: "12345"},
api.Update{Op: "set", Member: "description", Value: "new"},
}
client.On("Patch", "http://localhost/v2/servers/test/va1testserver01", update, mock.Anything).Return(nil)
service := server.New(client)
name := "va1testserver01"
err := service.Edit(name, server.UpdateGroup("12345"), server.UpdateDescription("new"))
assert.Nil(err)
client.AssertExpectations(t)
}