Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cloudfoundry/go-cfclient
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.0-alpha.9
Choose a base ref
...
head repository: cloudfoundry/go-cfclient
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.0-alpha.10
Choose a head ref

Commits on Aug 10, 2024

  1. Copy the full SHA
    cbb6c34 View commit details

Commits on Aug 13, 2024

  1. Merge pull request #429 from laidbackware/rolling-restart

    Add rolling restart to deployment client
    sneal authored Aug 13, 2024
    Copy the full SHA
    ef5bec8 View commit details

Commits on Nov 13, 2024

  1. Add updated dependencies

    sneal committed Nov 13, 2024
    Copy the full SHA
    fc11052 View commit details
  2. Merge pull request #433 from cloudfoundry/update-deps

    Add updated dependencies target
    sneal authored Nov 13, 2024
    Copy the full SHA
    79b9c38 View commit details

Commits on Nov 25, 2024

  1. Bump github.com/stretchr/testify from 1.9.0 to 1.10.0

    Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.9.0 to 1.10.0.
    - [Release notes](https://github.com/stretchr/testify/releases)
    - [Commits](stretchr/testify@v1.9.0...v1.10.0)
    
    ---
    updated-dependencies:
    - dependency-name: github.com/stretchr/testify
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Nov 25, 2024
    Copy the full SHA
    082811b View commit details
  2. Merge pull request #435 from cloudfoundry/dependabot/go_modules/githu…

    …b.com/stretchr/testify-1.10.0
    
    Bump github.com/stretchr/testify from 1.9.0 to 1.10.0
    sneal authored Nov 25, 2024
    Copy the full SHA
    c4d2226 View commit details

Commits on Dec 9, 2024

  1. Copy the full SHA
    c9254bf View commit details

Commits on Dec 19, 2024

  1. Copy the full SHA
    091d7ba View commit details

Commits on Dec 20, 2024

  1. Merge pull request #439 from metskem/main

    add ProcessStat fields cpu_entitlement and log_rate
    sneal authored Dec 20, 2024
    Copy the full SHA
    f44ff83 View commit details
  2. Copy the full SHA
    fa70a6a View commit details
  3. Merge pull request #440 from cloudfoundry/add-cpu-entitlement

    Add cpu_entitlement and log_rate to process stats test
    sneal authored Dec 20, 2024
    Copy the full SHA
    7306db9 View commit details

Commits on Jan 6, 2025

  1. Bump golang.org/x/oauth2 from 0.24.0 to 0.25.0

    Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.24.0 to 0.25.0.
    - [Commits](golang/oauth2@v0.24.0...v0.25.0)
    
    ---
    updated-dependencies:
    - dependency-name: golang.org/x/oauth2
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jan 6, 2025
    Copy the full SHA
    a4268ee View commit details

Commits on Jan 9, 2025

  1. Merge pull request #441 from cloudfoundry/dependabot/go_modules/golan…

    …g.org/x/oauth2-0.25.0
    
    Bump golang.org/x/oauth2 from 0.24.0 to 0.25.0
    sneal authored Jan 9, 2025
    Copy the full SHA
    0c61a55 View commit details

Commits on Jan 14, 2025

  1. Copy the full SHA
    a86a3cc View commit details
  2. Merge pull request #442 from peterhaochen47/pr/main/add_current_dropl…

    …et_to_app
    
    feat: add "relationships.current_droplet" to app resource
    sneal authored Jan 14, 2025
    Copy the full SHA
    3e04e4a View commit details

Commits on Feb 5, 2025

  1. build(deps): bump golang.org/x/oauth2 from 0.25.0 to 0.26.0

    Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.25.0 to 0.26.0.
    - [Commits](golang/oauth2@v0.25.0...v0.26.0)
    
    ---
    updated-dependencies:
    - dependency-name: golang.org/x/oauth2
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Feb 5, 2025
    Copy the full SHA
    5d62727 View commit details
  2. Merge pull request #443 from cloudfoundry/dependabot/go_modules/golan…

    …g.org/x/oauth2-0.26.0
    
    build(deps): bump golang.org/x/oauth2 from 0.25.0 to 0.26.0
    sneal authored Feb 5, 2025
    Copy the full SHA
    92b0d98 View commit details

Commits on Feb 6, 2025

  1. Fix: Provide empty context without deadline

    The request context has set up a deadline of value DefaultRequestTimeout.
    The function CreateOAuth2TokenSource would store that context in the
    token source creator. The token source creator would later try to create
    a new Token(), but fail since the deadline would be reached.
    
    The context passed to oauth2 package controls which HTTP client is used.
    See the oauth2.HTTPClient variable.
    
    Therefore fix the situation by passing an empty context to oauth2
    package.
    
    Fixes #444
    gogolok committed Feb 6, 2025
    Copy the full SHA
    4e5f7b5 View commit details

Commits on Feb 12, 2025

  1. Merge pull request #445 from stackitcloud/fix_token_source_context

    Fix: Provide empty context without deadline
    sneal authored Feb 12, 2025
    Copy the full SHA
    f0d18d4 View commit details
  2. Copy the full SHA
    5610a4b View commit details
  3. Merge pull request #448 from cloudfoundry/fix-local-golangci-lint

    Add corrected golangci-lint path to match installer
    sneal authored Feb 12, 2025
    Copy the full SHA
    2521905 View commit details
  4. Copy the full SHA
    2f0d21f View commit details
  5. Merge pull request #449 from cloudfoundry/fix-paid-services-allowed

    Add paid services allowed as non-pointer bool
    sneal authored Feb 12, 2025
    Copy the full SHA
    2b865aa View commit details

Commits on Feb 14, 2025

  1. Add job polling tests

    sneal committed Feb 14, 2025
    Copy the full SHA
    d3ab469 View commit details
  2. Copy the full SHA
    bee15db View commit details
  3. Copy the full SHA
    96a1439 View commit details
  4. Copy the full SHA
    39f5d34 View commit details
  5. Merge pull request #450 from cloudfoundry/verbose-error-polling

    Verbose error polling
    sneal authored Feb 14, 2025
    Copy the full SHA
    6a13539 View commit details

Commits on Feb 15, 2025

  1. Add cleaner options tests

    sneal committed Feb 15, 2025
    Copy the full SHA
    a7122e1 View commit details

Commits on Feb 25, 2025

  1. build(deps): bump golang.org/x/oauth2 from 0.26.0 to 0.27.0

    Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.26.0 to 0.27.0.
    - [Commits](golang/oauth2@v0.26.0...v0.27.0)
    
    ---
    updated-dependencies:
    - dependency-name: golang.org/x/oauth2
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Feb 25, 2025
    Copy the full SHA
    b5bf743 View commit details
  2. Copy the full SHA
    1bbbb17 View commit details
  3. Merge pull request #452 from cloudfoundry/issue-446

    Fix Issue 446
    sneal authored Feb 25, 2025
    Copy the full SHA
    e57bd27 View commit details
  4. Merge pull request #451 from cloudfoundry/dependabot/go_modules/golan…

    …g.org/x/oauth2-0.27.0
    
    build(deps): bump golang.org/x/oauth2 from 0.26.0 to 0.27.0
    sneal authored Feb 25, 2025
    Copy the full SHA
    e37deb2 View commit details
  5. Add bump to go 1.23

    - removed deprecated rand for test object generation
    sneal committed Feb 25, 2025
    1
    Copy the full SHA
    5a445c2 View commit details
  6. Merge pull request #453 from cloudfoundry/go-1.23

    Add bump to go 1.23
    sneal authored Feb 25, 2025
    Copy the full SHA
    9b8f5fc View commit details
  7. Copy the full SHA
    f3996c4 View commit details
  8. Merge pull request #454 from cloudfoundry/filtering-usage

    Add missing filtering link to usage section
    sneal authored Feb 25, 2025
    Copy the full SHA
    73c475c View commit details
Showing with 335 additions and 161 deletions.
  1. +5 −1 Makefile
  2. +37 −0 README.md
  3. +1 −1 client/app_features_test.go
  4. +1 −1 client/app_test.go
  5. +1 −1 client/app_usage_test.go
  6. +1 −1 client/audit_event_test.go
  7. +6 −3 client/build.go
  8. +1 −1 client/build_test.go
  9. +1 −1 client/buildpack_test.go
  10. +1 −0 client/deployment.go
  11. +1 −1 client/deployment_test.go
  12. +1 −1 client/domain_test.go
  13. +1 −1 client/droplet_test.go
  14. +1 −1 client/envar_group_test.go
  15. +1 −1 client/feature_flag_test.go
  16. +43 −21 client/filter.go
  17. +1 −1 client/isolation_segment_test.go
  18. +10 −12 client/job.go
  19. +43 −2 client/job_test.go
  20. +6 −6 client/list_opt.go
  21. +35 −31 client/list_opt_test.go
  22. +1 −1 client/manifest_test.go
  23. +1 −1 client/organization_quota_test.go
  24. +1 −1 client/organization_test.go
  25. +3 −3 client/package.go
  26. +3 −3 client/package_test.go
  27. +4 −4 client/polling.go
  28. +12 −8 client/polling_test.go
  29. +1 −1 client/process_test.go
  30. +1 −1 client/resource_match_test.go
  31. +1 −1 client/revision_test.go
  32. +1 −1 client/role_test.go
  33. +1 −1 client/route_test.go
  34. +1 −1 client/security_group_test.go
  35. +1 −1 client/service_broker_test.go
  36. +1 −1 client/service_credential_binding_test.go
  37. +1 −1 client/service_instance_test.go
  38. +1 −1 client/service_offering_test.go
  39. +1 −1 client/service_plan_test.go
  40. +1 −1 client/service_plan_visibility_test.go
  41. +1 −1 client/service_route_binding_test.go
  42. +1 −1 client/service_usage_test.go
  43. +1 −1 client/sidecar_test.go
  44. +1 −1 client/space_quota_test.go
  45. +1 −1 client/space_test.go
  46. +1 −1 client/stack_test.go
  47. +1 −1 client/task_test.go
  48. +1 −1 client/user_test.go
  49. +5 −3 go.mod
  50. +5 −4 go.sum
  51. +1 −1 internal/http/client.go
  52. +1 −1 internal/http/client_test.go
  53. +3 −3 operation/push.go
  54. +1 −1 operation/push_test.go
  55. +5 −5 resource/app.go
  56. +1 −1 resource/organization_quota.go
  57. +6 −4 resource/process.go
  58. +1 −1 resource/quota.go
  59. +1 −1 resource/space_quota.go
  60. +5 −0 resource/types.go
  61. +12 −3 testutil/name_generator.go
  62. +8 −3 testutil/object_generator.go
  63. +5 −0 testutil/template/app.json
  64. +29 −0 testutil/template/job_failed.json
  65. +3 −1 testutil/template/process_stats.json
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -27,7 +27,11 @@ endif

.PHONY: lint
lint: lint-prepare ## Run the golangci linter
golangci-lint run
./bin/golangci-lint run

.PHONY: update
update: ## Update all dependencies
go get -u ./... && go mod tidy

.PHONY: tidy
tidy: ## Remove unused dependencies
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ library will cut releases that will be tagged with v3.0.0, v3.0.1 etc, see the V
## Usage
- [Authentication](./README.md#authentication)
- [Resources](./README.md#resources)
- [Filtering](./README.md#filtering)
- [Pagination](./README.md#pagination)
- [Asynchronous Jobs](./README.md#asynchronous-jobs)
- [Error Handling](./README.md#error-handling)
@@ -82,6 +83,42 @@ __NOTE__ - Using the context package you can easily pass cancellation signals an
for handling a request. In case there is no context available, then `context.Background()` can be used as a starting
point.

### Filtering
This library should support all possible
[filtering combinations that the CF API supports](https://v3-apidocs.cloudfoundry.org/version/3.188.0/index.html#filters),
including those that may not be valid. While the library tries to steer you in a direction that won't allow for invalid
combinations it's still possible to create filters that are nonsensical. The support matrix for filters:

| Type | Multi-valued | Empty | Relational Op | Not |
| --- | --- | --- | --- | --- |
| Timestamp | x | | x | x |
| String | x | x | | x |

Full filtering example, find all apps with the name of spring-music:
```go
opts := client.NewAppListOptions()
opts.Names.EqualTo("spring-music")
apps, _ := cf.Applications.ListAll(context.Background(), opts)
fmt.Printf("Found %d apps named spring-music\n", len(apps))
```

Find multiple applications with specific names:
```go
opts.Names.EqualTo("credit-processor-service", "credit-processor-ui")
```

Find all apps not named spring-music:
```go
opts.Names.NotEqualTo("spring-music")
```

Find all spring-music apps created within a date range:
```go
opts.Names.EqualTo("spring-music")
opts.CreateAts.After(date1)
opts.CreateAts.Before(date2)
```

### Pagination
All requests for resource collections (apps, orgs, spaces etc) support pagination. Pagination options are described
in the client.ListOptions struct and passed to the list methods directly or as an embedded type of a more specific
2 changes: 1 addition & 1 deletion client/app_features_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
)

func TestAppFeatures(t *testing.T) {
g := testutil.NewObjectJSONGenerator(163)
g := testutil.NewObjectJSONGenerator()
appFeature := g.AppFeature().JSON

tests := []RouteTest{
2 changes: 1 addition & 1 deletion client/app_test.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
)

func TestApps(t *testing.T) {
g := testutil.NewObjectJSONGenerator(1)
g := testutil.NewObjectJSONGenerator()
app1 := g.Application().JSON
app2 := g.Application().JSON
app3 := g.Application().JSON
2 changes: 1 addition & 1 deletion client/app_usage_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
)

func TestAppUsages(t *testing.T) {
g := testutil.NewObjectJSONGenerator(161)
g := testutil.NewObjectJSONGenerator()
appUsage := g.AppUsage().JSON
appUsage2 := g.AppUsage().JSON
appUsage3 := g.AppUsage().JSON
2 changes: 1 addition & 1 deletion client/audit_event_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
)

func TestAuditEvents(t *testing.T) {
g := testutil.NewObjectJSONGenerator(161)
g := testutil.NewObjectJSONGenerator()
auditEvent := g.AuditEvent().JSON
auditEvent2 := g.AuditEvent().JSON
auditEvent3 := g.AuditEvent().JSON
9 changes: 6 additions & 3 deletions client/build.go
Original file line number Diff line number Diff line change
@@ -138,12 +138,15 @@ func (c *BuildClient) ListForAppAll(ctx context.Context, appGUID string, opts *B

// PollStaged waits until the build is staged, fails, or times out
func (c *BuildClient) PollStaged(ctx context.Context, guid string, opts *PollingOptions) error {
return PollForStateOrTimeout(func() (string, error) {
return PollForStateOrTimeout(func() (string, string, error) {
build, err := c.Get(ctx, guid)
if build != nil {
return string(build.State), err
if build.Error != nil {
return string(build.State), *build.Error, err
}
return string(build.State), "", err
}
return "", err
return "", "", err
}, string(resource.BuildStateStaged), opts)
}

2 changes: 1 addition & 1 deletion client/build_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
)

func TestBuilds(t *testing.T) {
g := testutil.NewObjectJSONGenerator(2)
g := testutil.NewObjectJSONGenerator()
build := g.Build("STAGED").JSON
build2 := g.Build("STAGED").JSON
build3 := g.Build("STAGED").JSON
2 changes: 1 addition & 1 deletion client/buildpack_test.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
)

func TestBuildpacks(t *testing.T) {
g := testutil.NewObjectJSONGenerator(1002)
g := testutil.NewObjectJSONGenerator()
buildpack := g.Buildpack().JSON
buildpack2 := g.Buildpack().JSON
buildpack3 := g.Buildpack().JSON
1 change: 1 addition & 0 deletions client/deployment.go
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ func (c *DeploymentClient) Cancel(ctx context.Context, guid string) error {
}

// Create a new deployment
// Rolling restart can be triggered by passing in the app guid and existing droplet guid
func (c *DeploymentClient) Create(ctx context.Context, r *resource.DeploymentCreate) (*resource.Deployment, error) {
// validate the params
if r.Droplet != nil && r.Revision != nil {
2 changes: 1 addition & 1 deletion client/deployment_test.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import (
)

func TestDeployments(t *testing.T) {
g := testutil.NewObjectJSONGenerator(4)
g := testutil.NewObjectJSONGenerator()
deployment := g.Deployment().JSON
deployment2 := g.Deployment().JSON
deployment3 := g.Deployment().JSON
2 changes: 1 addition & 1 deletion client/domain_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
)

func TestDomains(t *testing.T) {
g := testutil.NewObjectJSONGenerator(1)
g := testutil.NewObjectJSONGenerator()
domain := g.Domain().JSON
domain2 := g.Domain().JSON
domain3 := g.Domain().JSON
2 changes: 1 addition & 1 deletion client/droplet_test.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import (
)

func TestDroplets(t *testing.T) {
g := testutil.NewObjectJSONGenerator(2)
g := testutil.NewObjectJSONGenerator()
droplet := g.Droplet().JSON
droplet2 := g.Droplet().JSON
droplet3 := g.Droplet().JSON
2 changes: 1 addition & 1 deletion client/envar_group_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
)

func TestEnvVarGroups(t *testing.T) {
g := testutil.NewObjectJSONGenerator(852)
g := testutil.NewObjectJSONGenerator()
envVarGroup := g.EnvVarGroup().JSON

tests := []RouteTest{
2 changes: 1 addition & 1 deletion client/feature_flag_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
)

func TestFeatureFlags(t *testing.T) {
g := testutil.NewObjectJSONGenerator(852)
g := testutil.NewObjectJSONGenerator()
ff := g.FeatureFlag().JSON
ff2 := g.FeatureFlag().JSON
ff3 := g.FeatureFlag().JSON
64 changes: 43 additions & 21 deletions client/filter.go
Original file line number Diff line number Diff line change
@@ -30,41 +30,63 @@ func (r FilterModifier) String() string {
return ""
}

type TimestampFilterList []TimestampFilter

type TimestampFilter struct {
Timestamp []time.Time
Operator FilterModifier
}

func (t *TimestampFilter) EqualTo(createdAt ...time.Time) {
t.Timestamp = createdAt
func (tl *TimestampFilterList) EqualTo(ts ...time.Time) {
*tl = append(*tl, TimestampFilter{
Timestamp: ts,
})
}

func (t *TimestampFilter) Before(createdAt time.Time) {
t.Timestamp = []time.Time{
createdAt,
}
t.Operator = FilterModifierLessThan
func (tl *TimestampFilterList) Before(ts time.Time) {
*tl = append(*tl, TimestampFilter{
Timestamp: []time.Time{
ts,
},
Operator: FilterModifierLessThan,
})
}

func (t *TimestampFilter) BeforeOrEqualTo(createdAt time.Time) {
t.Timestamp = []time.Time{
createdAt,
}
t.Operator = FilterModifierLessThanOrEqual
func (tl *TimestampFilterList) BeforeOrEqualTo(ts time.Time) {
*tl = append(*tl, TimestampFilter{
Timestamp: []time.Time{
ts,
},
Operator: FilterModifierLessThanOrEqual,
})
}

func (t *TimestampFilter) After(createdAt time.Time) {
t.Timestamp = []time.Time{
createdAt,
}
t.Operator = FilterModifierGreaterThan
func (tl *TimestampFilterList) After(ts time.Time) {
*tl = append(*tl, TimestampFilter{
Timestamp: []time.Time{
ts,
},
Operator: FilterModifierGreaterThan,
})
}

func (t *TimestampFilter) AfterOrEqualTo(createdAt time.Time) {
t.Timestamp = []time.Time{
createdAt,
func (tl *TimestampFilterList) AfterOrEqualTo(ts time.Time) {
*tl = append(*tl, TimestampFilter{
Timestamp: []time.Time{
ts,
},
Operator: FilterModifierGreaterThanOrEqual,
})
}

func (tl TimestampFilterList) Serialize(values url.Values, tag string) error {
for _, t := range tl {
err := t.Serialize(values, tag)
if err != nil {
return err
}
}
t.Operator = FilterModifierGreaterThanOrEqual
return nil
}

func (t TimestampFilter) Serialize(values url.Values, tag string) error {
2 changes: 1 addition & 1 deletion client/isolation_segment_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
)

func TestIsolationSegments(t *testing.T) {
g := testutil.NewObjectJSONGenerator(1)
g := testutil.NewObjectJSONGenerator()
iso := g.IsolationSegment().JSON
iso2 := g.IsolationSegment().JSON
iso3 := g.IsolationSegment().JSON
22 changes: 10 additions & 12 deletions client/job.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package client

import (
"context"

"github.com/cloudfoundry/go-cfclient/v3/internal/path"
"github.com/cloudfoundry/go-cfclient/v3/resource"
)
@@ -21,20 +20,19 @@ func (c *JobClient) Get(ctx context.Context, guid string) (*resource.Job, error)

// PollComplete waits until the job completes, fails, or times out
func (c *JobClient) PollComplete(ctx context.Context, jobGUID string, opts *PollingOptions) error {
err := PollForStateOrTimeout(func() (string, error) {
err := PollForStateOrTimeout(func() (string, string, error) {
job, err := c.Get(ctx, jobGUID)
if job != nil {
return string(job.State), err
var cfErrors string
for _, e := range job.Errors {
cfErrors += "\n" + e.Error()
}
for _, e := range job.Warnings {
cfErrors += "\n" + e.Detail
}
return string(job.State), cfErrors, err
}
return "", err
return "", "", err
}, string(resource.JobStateComplete), opts)

// attempt to return the underlying saved job error
if err == AsyncProcessFailedError {
job, _ := c.Get(ctx, jobGUID)
if job != nil && len(job.Errors) > 0 {
return job.Errors[0]
}
}
return err
}
45 changes: 43 additions & 2 deletions client/job_test.go
Original file line number Diff line number Diff line change
@@ -2,15 +2,24 @@ package client

import (
"context"
"github.com/stretchr/testify/require"
"net/http"
"testing"
"time"

"github.com/cloudfoundry/go-cfclient/v3/testutil"
)

func TestJobs(t *testing.T) {
g := testutil.NewObjectJSONGenerator(1)
g := testutil.NewObjectJSONGenerator()
job := g.Job("COMPLETE").JSON
jobProcessing := g.Job("PROCESSING").JSON
jobFailed := g.JobFailed().JSON
pollingOpts := &PollingOptions{
FailedState: "FAILED",
Timeout: time.Second,
CheckInterval: time.Nanosecond,
}

tests := []RouteTest{
{
@@ -19,12 +28,44 @@ func TestJobs(t *testing.T) {
Method: "GET",
Endpoint: "/v3/jobs/c33a5caf-77e0-4d6e-b587-5555d339bc9a",
Output: g.Single(job),
Status: http.StatusOK},
Status: http.StatusOK,
},
Expected: job,
Action: func(c *Client, t *testing.T) (any, error) {
return c.Jobs.Get(context.Background(), "c33a5caf-77e0-4d6e-b587-5555d339bc9a")
},
},
{
Description: "Poll job that succeeds",
Route: testutil.MockRoute{
Method: "GET",
Endpoint: "/v3/jobs/c33a5caf-77e0-4d6e-b587-5555d339bc9a",
Output: []string{jobProcessing, job},
Statuses: []int{http.StatusOK, http.StatusOK},
},
Action: func(c *Client, t *testing.T) (any, error) {
err := c.Jobs.PollComplete(context.Background(), "c33a5caf-77e0-4d6e-b587-5555d339bc9a", pollingOpts)
return nil, err
},
},
{
Description: "Poll job that fails",
Route: testutil.MockRoute{
Method: "GET",
Endpoint: "/v3/jobs/40e49716-44a3-4ae9-9926-d1a804acf70c",
Output: []string{jobProcessing, jobFailed},
Statuses: []int{http.StatusOK, http.StatusOK},
},
Action: func(c *Client, t *testing.T) (any, error) {
err := c.Jobs.PollComplete(context.Background(), "40e49716-44a3-4ae9-9926-d1a804acf70c", pollingOpts)
require.Error(t, err)
require.ErrorContains(t, err, "received state FAILED while waiting for async process")
require.ErrorContains(t, err, "cfclient error (CF-UnprocessableEntity|10008): something went wrong")
require.ErrorContains(t, err, "cfclient error (UnknownError|10001): unexpected error occurred")
require.ErrorContains(t, err, "some warning")
return nil, nil
},
},
}
ExecuteTests(tests, t)
}
Loading