diff --git a/droplets.go b/droplets.go index 2ddd7d6b..6f323c27 100644 --- a/droplets.go +++ b/droplets.go @@ -66,6 +66,7 @@ type Droplet struct { Tags []string `json:"tags,omitempty"` VolumeIDs []string `json:"volume_ids"` VPCUUID string `json:"vpc_uuid,omitempty"` + ProjectID string `json:"project_id,omitempty"` } // PublicIPv4 returns the public IPv4 address for the Droplet. @@ -230,6 +231,7 @@ type DropletCreateRequest struct { IPv6 bool `json:"ipv6"` PrivateNetworking bool `json:"private_networking"` Monitoring bool `json:"monitoring"` + ProjectID string `json:"project_id"` UserData string `json:"user_data,omitempty"` Volumes []DropletCreateVolume `json:"volumes,omitempty"` Tags []string `json:"tags"` @@ -249,6 +251,7 @@ type DropletMultiCreateRequest struct { IPv6 bool `json:"ipv6"` PrivateNetworking bool `json:"private_networking"` Monitoring bool `json:"monitoring"` + ProjectID string `json:"project_id"` UserData string `json:"user_data,omitempty"` Tags []string `json:"tags"` VPCUUID string `json:"vpc_uuid,omitempty"` diff --git a/droplets_test.go b/droplets_test.go index 2b510ac8..7555030b 100644 --- a/droplets_test.go +++ b/droplets_test.go @@ -319,9 +319,10 @@ func TestDroplets_Create(t *testing.T) { {ID: "hello-im-another-volume"}, {Name: "should be ignored due to Name", ID: "aaa-111-bbb-222-ccc"}, }, - Tags: []string{"one", "two"}, - VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6", - Backups: true, + Tags: []string{"one", "two"}, + VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6", + ProjectID: "88b72d1a-b78a-4d9f-9090-b53c4399073f", + Backups: true, BackupPolicy: &DropletBackupPolicyRequest{ Plan: "weekly", Weekday: "MON", @@ -345,6 +346,7 @@ func TestDroplets_Create(t *testing.T) { }, "tags": []interface{}{"one", "two"}, "vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6", + "project_id": "88b72d1a-b78a-4d9f-9090-b53c4399073f", "backups": true, "backup_policy": map[string]interface{}{"plan": "weekly", "weekday": "MON", "hour": float64(0)}, } @@ -416,6 +418,7 @@ func TestDroplets_CreateWithoutDropletAgent(t *testing.T) { }, Tags: []string{"one", "two"}, VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6", + ProjectID: "88b72d1a-b78a-4d9f-9090-b53c4399073f", WithDropletAgent: &boolVal, } @@ -436,6 +439,7 @@ func TestDroplets_CreateWithoutDropletAgent(t *testing.T) { }, "tags": []interface{}{"one", "two"}, "vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6", + "project_id": "88b72d1a-b78a-4d9f-9090-b53c4399073f", "with_droplet_agent": false, } jsonBlob := ` @@ -497,15 +501,15 @@ func TestDroplets_WithDropletAgentJsonMarshal(t *testing.T) { }{ { in: &DropletCreateRequest{Name: "foo", WithDropletAgent: &boolF}, - want: `{"name":"foo","region":"","size":"","image":0,"ssh_keys":null,"backups":false,"ipv6":false,"private_networking":false,"monitoring":false,"tags":null,"with_droplet_agent":false}`, + want: `{"name":"foo","region":"","size":"","image":0,"ssh_keys":null,"backups":false,"ipv6":false,"private_networking":false,"monitoring":false,"project_id":"","tags":null,"with_droplet_agent":false}`, }, { in: &DropletCreateRequest{Name: "foo", WithDropletAgent: &boolT}, - want: `{"name":"foo","region":"","size":"","image":0,"ssh_keys":null,"backups":false,"ipv6":false,"private_networking":false,"monitoring":false,"tags":null,"with_droplet_agent":true}`, + want: `{"name":"foo","region":"","size":"","image":0,"ssh_keys":null,"backups":false,"ipv6":false,"private_networking":false,"monitoring":false,"project_id":"","tags":null,"with_droplet_agent":true}`, }, { in: &DropletCreateRequest{Name: "foo"}, - want: `{"name":"foo","region":"","size":"","image":0,"ssh_keys":null,"backups":false,"ipv6":false,"private_networking":false,"monitoring":false,"tags":null}`, + want: `{"name":"foo","region":"","size":"","image":0,"ssh_keys":null,"backups":false,"ipv6":false,"private_networking":false,"monitoring":false,"project_id":"","tags":null}`, }, } @@ -535,8 +539,9 @@ func TestDroplets_CreateWithDisabledPublicNetworking(t *testing.T) { {ID: "hello-im-another-volume"}, {Name: "should be ignored due to Name", ID: "aaa-111-bbb-222-ccc"}, }, - Tags: []string{"one", "two"}, - VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6", + Tags: []string{"one", "two"}, + VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6", + ProjectID: "88b72d1a-b78a-4d9f-9090-b53c4399073f", } mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) { @@ -554,8 +559,9 @@ func TestDroplets_CreateWithDisabledPublicNetworking(t *testing.T) { map[string]interface{}{"id": "hello-im-another-volume"}, map[string]interface{}{"id": "aaa-111-bbb-222-ccc"}, }, - "tags": []interface{}{"one", "two"}, - "vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6", + "tags": []interface{}{"one", "two"}, + "vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6", + "project_id": "88b72d1a-b78a-4d9f-9090-b53c4399073f", } jsonBlob := ` { @@ -609,8 +615,9 @@ func TestDroplets_CreateMultiple(t *testing.T) { Image: DropletCreateImage{ ID: 1, }, - Tags: []string{"one", "two"}, - VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6", + Tags: []string{"one", "two"}, + VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6", + ProjectID: "88b72d1a-b78a-4d9f-9090-b53c4399073f", } mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) { @@ -626,6 +633,7 @@ func TestDroplets_CreateMultiple(t *testing.T) { "monitoring": false, "tags": []interface{}{"one", "two"}, "vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6", + "project_id": "88b72d1a-b78a-4d9f-9090-b53c4399073f", } jsonBlob := ` { diff --git a/godo_test.go b/godo_test.go index e7575ac9..4d7eaaf6 100644 --- a/godo_test.go +++ b/godo_test.go @@ -182,7 +182,7 @@ func TestNewRequest(t *testing.T) { inBody, outBody := &DropletCreateRequest{Name: "l"}, `{"name":"l","region":"","size":"","image":0,`+ `"ssh_keys":null,"backups":false,"ipv6":false,`+ - `"private_networking":false,"monitoring":false,"tags":null}`+"\n" + `"private_networking":false,"monitoring":false,"project_id":"","tags":null}`+"\n" req, _ := c.NewRequest(ctx, http.MethodPost, inURL, inBody) // test relative URL was expanded @@ -233,7 +233,7 @@ func TestNewRequest_withUserData(t *testing.T) { inBody, outBody := &DropletCreateRequest{Name: "l", UserData: "u"}, `{"name":"l","region":"","size":"","image":0,`+ `"ssh_keys":null,"backups":false,"ipv6":false,`+ - `"private_networking":false,"monitoring":false,"user_data":"u","tags":null}`+"\n" + `"private_networking":false,"monitoring":false,"project_id":"","user_data":"u","tags":null}`+"\n" req, _ := c.NewRequest(ctx, http.MethodPost, inURL, inBody) // test relative URL was expanded @@ -262,7 +262,7 @@ func TestNewRequest_withDropletAgent(t *testing.T) { inBody, outBody := &DropletCreateRequest{Name: "l", WithDropletAgent: &boolVal}, `{"name":"l","region":"","size":"","image":0,`+ `"ssh_keys":null,"backups":false,"ipv6":false,`+ - `"private_networking":false,"monitoring":false,"tags":null,"with_droplet_agent":true}`+"\n" + `"private_networking":false,"monitoring":false,"project_id":"","tags":null,"with_droplet_agent":true}`+"\n" req, _ := c.NewRequest(ctx, http.MethodPost, inURL, inBody) // test relative URL was expanded