Skip to content

Commit

Permalink
Update ServerCreateOpts to use pointers (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
thcyron authored and thetechnick committed Jan 16, 2018
1 parent 5b61ce7 commit 197f445
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions hcloud/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func (c *ServerClient) All(ctx context.Context) ([]*Server, error) {
// ServerCreateOpts specifies options for creating a new server.
type ServerCreateOpts struct {
Name string
ServerType ServerType
Image Image
ServerType *ServerType
Image *Image
SSHKeys []*SSHKey
Location *Location
Datacenter *Datacenter
Expand All @@ -197,10 +197,10 @@ func (o ServerCreateOpts) Validate() error {
if o.Name == "" {
return errors.New("missing name")
}
if o.ServerType.ID == 0 && o.ServerType.Name == "" {
if o.ServerType == nil || (o.ServerType.ID == 0 && o.ServerType.Name == "") {
return errors.New("missing server type")
}
if o.Image.ID == 0 && o.Image.Name == "" {
if o.Image == nil || (o.Image.ID == 0 && o.Image.Name == "") {
return errors.New("missing image")
}
if o.Location != nil && o.Datacenter != nil {
Expand Down
24 changes: 12 additions & 12 deletions hcloud/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ func TestServersCreateWithSSHKeys(t *testing.T) {
ctx := context.Background()
result, _, err := env.Client.Server.Create(ctx, ServerCreateOpts{
Name: "test",
ServerType: ServerType{ID: 1},
Image: Image{ID: 2},
ServerType: &ServerType{ID: 1},
Image: &Image{ID: 2},
SSHKeys: []*SSHKey{
{ID: 1},
{ID: 2},
Expand Down Expand Up @@ -276,8 +276,8 @@ func TestServersCreateWithoutSSHKeys(t *testing.T) {
ctx := context.Background()
result, _, err := env.Client.Server.Create(ctx, ServerCreateOpts{
Name: "test",
ServerType: ServerType{ID: 1},
Image: Image{ID: 2},
ServerType: &ServerType{ID: 1},
Image: &Image{ID: 2},
})
if err != nil {
t.Fatalf("Server.Create failed: %s", err)
Expand Down Expand Up @@ -315,8 +315,8 @@ func TestServersCreateWithDatacenterID(t *testing.T) {
ctx := context.Background()
result, _, err := env.Client.Server.Create(ctx, ServerCreateOpts{
Name: "test",
ServerType: ServerType{ID: 1},
Image: Image{ID: 2},
ServerType: &ServerType{ID: 1},
Image: &Image{ID: 2},
Datacenter: &Datacenter{ID: 1},
})
if err != nil {
Expand Down Expand Up @@ -349,8 +349,8 @@ func TestServersCreateWithDatacenterName(t *testing.T) {
ctx := context.Background()
result, _, err := env.Client.Server.Create(ctx, ServerCreateOpts{
Name: "test",
ServerType: ServerType{ID: 1},
Image: Image{ID: 2},
ServerType: &ServerType{ID: 1},
Image: &Image{ID: 2},
Datacenter: &Datacenter{Name: "dc1"},
})
if err != nil {
Expand Down Expand Up @@ -383,8 +383,8 @@ func TestServersCreateWithLocationID(t *testing.T) {
ctx := context.Background()
result, _, err := env.Client.Server.Create(ctx, ServerCreateOpts{
Name: "test",
ServerType: ServerType{ID: 1},
Image: Image{ID: 2},
ServerType: &ServerType{ID: 1},
Image: &Image{ID: 2},
Location: &Location{ID: 1},
})
if err != nil {
Expand Down Expand Up @@ -417,8 +417,8 @@ func TestServersCreateWithLocationName(t *testing.T) {
ctx := context.Background()
result, _, err := env.Client.Server.Create(ctx, ServerCreateOpts{
Name: "test",
ServerType: ServerType{ID: 1},
Image: Image{ID: 2},
ServerType: &ServerType{ID: 1},
Image: &Image{ID: 2},
Location: &Location{Name: "loc1"},
})
if err != nil {
Expand Down

0 comments on commit 197f445

Please sign in to comment.