Repository: cloudflare/cloudflare-go
Pull request #1188 (2023-01-27 15:28:01)

UpdateQueue function now matches API docs and allows a Queue's name t…
## Description

The existing UpdateQueue implementation was not quite correct. The API endpoint only allows for updating a Queue's name. The existing name is passed in the URL, while the new name is passed as a parameter in the body. This PR updates the function to match the API expectations.

## Has your change been tested?

* Updated unit test
* Tested manually with local terraform provider changes to update a Queue's name

## Screenshots (if appropriate):

## Types of changes

What sort of change does your code introduce/modify?

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented (api.cloudflare.com or developers.cloudflare.com) and stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/



Patch:
diff --git a/.changelog/1183.txt b/.changelog/1183.txt
deleted file mode 100644
index 01e394768..000000000
--- a/.changelog/1183.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-```release-note:enhancement
-rulesets: add support for `score_per_period` and `score_response_header_name`
-```
diff --git a/.changelog/1188.txt b/.changelog/1188.txt
new file mode 100644
index 000000000..b478f060d
--- /dev/null
+++ b/.changelog/1188.txt
@@ -0,0 +1,3 @@
+```release-note:breaking-change
+queues: UpdateQueue has been updated to match the API and now correctly updates a Queue's name
+```
\ No newline at end of file
diff --git a/.github/workflows/changelog-check.yml b/.github/workflows/changelog-check.yml
index 45b8c408b..dba1a7f54 100644
--- a/.github/workflows/changelog-check.yml
+++ b/.github/workflows/changelog-check.yml
@@ -3,13 +3,16 @@ on: [pull_request_target]
 
 jobs:
   changelog-check:
-    runs-on: ubuntu-latest
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-latest]
     steps:
       - uses: actions/checkout@v3
       - name: Set up Go
         uses: actions/setup-go@v3
         with:
-          go-version-file: 'internal/tools/go.mod'
+          go-version: ^1.17
       - run: go generate -tags tools internal/tools/tools.go
       - run: go run cmd/changelog-check/main.go ${{ github.event.pull_request.number }}
         working-directory: ./internal/tools
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index 57870aa4a..7dfe116df 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -4,11 +4,11 @@ jobs:
   coverage:
     runs-on: ubuntu-latest
     steps:
-      - name: Checkout code
-        uses: actions/checkout@v3
       - uses: actions/setup-go@v3
         with:
-          go-version-file: 'go.mod'
+          go-version: 1.18
+      - name: Checkout code
+        uses: actions/checkout@v3
       - uses: actions/cache@v3
         with:
           path: ~/go/pkg/mod
diff --git a/.github/workflows/generate-changelog.yml b/.github/workflows/generate-changelog.yml
index b8029ae78..341cf5c9d 100644
--- a/.github/workflows/generate-changelog.yml
+++ b/.github/workflows/generate-changelog.yml
@@ -8,12 +8,12 @@ jobs:
     if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch'
     runs-on: ubuntu-latest
     steps:
+      - uses: actions/setup-go@v3
+        with:
+          go-version: 1.18
       - uses: actions/checkout@v3
         with:
           fetch-depth: 0
-      - uses: actions/setup-go@v3
-        with:
-          go-version-file: 'internal/tools/go.mod'
       - run: go generate -tags tools internal/tools/tools.go
       - run: ./scripts/generate-changelog.sh
       - run: |
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 0830c1050..7063c4e37 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -15,7 +15,7 @@ jobs:
           fetch-depth: 0
       - uses: actions/setup-go@v3
         with:
-          go-version-file: 'go.mod'
+          go-version: ^1.17
       - name: Run GoReleaser
         uses: goreleaser/goreleaser-action@v4.1.0
         with:
diff --git a/queue.go b/queue.go
index 3b9aa5e90..771a1f148 100644
--- a/queue.go
+++ b/queue.go
@@ -78,14 +78,8 @@ type QueueConsumerResponse struct {
 }
 
 type UpdateQueueParams struct {
-	ID                  string          `json:"queue_id,omitempty"`
-	Name                string          `json:"queue_name,omitempty"`
-	CreatedOn           *time.Time      `json:"created_on,omitempty"`
-	ModifiedOn          *time.Time      `json:"modified_on,omitempty"`
-	ProducersTotalCount int             `json:"producers_total_count,omitempty"`
-	Producers           []QueueProducer `json:"producers,omitempty"`
-	ConsumersTotalCount int             `json:"consumers_total_count,omitempty"`
-	Consumers           []QueueConsumer `json:"consumers,omitempty"`
+	Name        string `json:"-"`
+	UpdatedName string `json:"queue_name,omitempty"`
 }
 
 type ListQueueConsumersParams struct {
@@ -233,12 +227,12 @@ func (api *API) UpdateQueue(ctx context.Context, rc *ResourceContainer, params U
 		return Queue{}, ErrMissingAccountID
 	}
 
-	if params.Name == "" {
+	if params.Name == "" || params.UpdatedName == "" {
 		return Queue{}, ErrMissingQueueName
 	}
 
 	uri := fmt.Sprintf("/accounts/%s/workers/queues/%s", rc.Identifier, params.Name)
-	res, err := api.makeRequestContext(ctx, http.MethodPut, uri, nil)
+	res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params)
 	if err != nil {
 		return Queue{}, fmt.Errorf("%s: %w", errMakeRequestError, err)
 	}
diff --git a/rulesets.go b/rulesets.go
index 27521b024..1f18d64a7 100644
--- a/rulesets.go
+++ b/rulesets.go
@@ -643,14 +643,12 @@ type RulesetRule struct {
 
 // RulesetRuleRateLimit contains the structure of a HTTP rate limit Ruleset Rule.
 type RulesetRuleRateLimit struct {
-	Characteristics         []string `json:"characteristics,omitempty"`
-	RequestsPerPeriod       int      `json:"requests_per_period,omitempty"`
-	ScorePerPeriod          int      `json:"score_per_period,omitempty"`
-	ScoreResponseHeaderName string   `json:"score_response_header_name,omitempty"`
-	Period                  int      `json:"period,omitempty"`
-	MitigationTimeout       int      `json:"mitigation_timeout,omitempty"`
-	CountingExpression      string   `json:"counting_expression,omitempty"`
-	RequestsToOrigin        bool     `json:"requests_to_origin,omitempty"`
+	Characteristics    []string `json:"characteristics,omitempty"`
+	RequestsPerPeriod  int      `json:"requests_per_period,omitempty"`
+	Period             int      `json:"period,omitempty"`
+	MitigationTimeout  int      `json:"mitigation_timeout,omitempty"`
+	CountingExpression string   `json:"counting_expression,omitempty"`
+	RequestsToOrigin   bool     `json:"requests_to_origin,omitempty"`
 }
 
 // RulesetRuleExposedCredentialCheck contains the structure of an exposed


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 087d4c4aa..a7cfdd13f 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -5,7 +5,8 @@ jobs:
     strategy:
       matrix:
         go-version: [1.17, 1.18, 1.19]
-    runs-on: ubuntu-latest
+        os: [ubuntu-latest, macos-latest, windows-latest]
+    runs-on: ${{ matrix.os }}
     steps:
       - uses: actions/setup-go@v3
         with:
diff --git a/queue_test.go b/queue_test.go
index 5485b354c..b175a7045 100644
--- a/queue_test.go
+++ b/queue_test.go
@@ -272,17 +272,17 @@ func TestQueue_Update(t *testing.T) {
 		}
 	}`)
 	})
-	_, err := client.UpdateQueue(context.Background(), AccountIdentifier(""), UpdateQueueParams{})
+	_, err := client.UpdateQueue(context.Background(), AccountIdentifier(""), UpdateQueueParams{Name: testQueueName})
 	if assert.Error(t, err) {
 		assert.Equal(t, ErrMissingAccountID, err)
 	}
 
-	_, err = client.UpdateQueue(context.Background(), AccountIdentifier(testAccountID), UpdateQueueParams{})
+	_, err = client.UpdateQueue(context.Background(), AccountIdentifier(testAccountID), UpdateQueueParams{Name: testQueueName})
 	if assert.Error(t, err) {
 		assert.Equal(t, ErrMissingQueueName, err)
 	}
 
-	results, err := client.UpdateQueue(context.Background(), AccountIdentifier(testAccountID), UpdateQueueParams{Name: "example-queue"})
+	results, err := client.UpdateQueue(context.Background(), AccountIdentifier(testAccountID), UpdateQueueParams{Name: testQueueName, UpdatedName: "renamed-example-queue"})
 	if assert.NoError(t, err) {
 		CreatedOn, _ := time.Parse(time.RFC3339, "2023-01-01T00:00:00Z")
 		ModifiedOn, _ := time.Parse(time.RFC3339, "2023-01-01T00:00:00Z")