Skip to content

Commit

Permalink
fix: pass context.Background() in all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ar3s3ru committed Jan 13, 2024
1 parent eca0be2 commit 043b90b
Show file tree
Hide file tree
Showing 44 changed files with 412 additions and 379 deletions.
2 changes: 1 addition & 1 deletion assigned_fulfillment_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestAssignedFulfillmentOrderGet(t *testing.T) {

// fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}

// fulfillment, err := fulfillmentOrderService.Get(255858046, nil)
// fulfillment, err := fulfillmentOrderService.Get(context.Background(), 255858046, nil)
// if err != nil {
// t.Errorf("FulfillmentOrder.Get returned error: %v", err)
// }
Expand Down
11 changes: 6 additions & 5 deletions carrier_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package goshopify

import (
"context"
"fmt"
"reflect"
"testing"
Expand All @@ -15,7 +16,7 @@ func TestCarrierList(t *testing.T) {
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/carrier_services.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("carrier_services.json")))

carriers, err := client.CarrierService.List()
carriers, err := client.CarrierService.List(context.Background())
if err != nil {
t.Errorf("Carrier.List returned error: %v", err)
}
Expand Down Expand Up @@ -44,7 +45,7 @@ func TestCarrierGet(t *testing.T) {
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/carrier_services/1.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("carrier_service.json")))

carrier, err := client.CarrierService.Get(1)
carrier, err := client.CarrierService.Get(context.Background(), 1)
if err != nil {
t.Errorf("Carrier.Get returned error: %v", err)
}
Expand All @@ -71,7 +72,7 @@ func TestCarrierCreate(t *testing.T) {
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/carrier_services.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("carrier_service.json")))

carrier, err := client.CarrierService.Create(CarrierService{})
carrier, err := client.CarrierService.Create(context.Background(), CarrierService{})
if err != nil {
t.Errorf("Carrier.Create returned error: %v", err)
}
Expand All @@ -98,7 +99,7 @@ func TestCarrierUpdate(t *testing.T) {
httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/carrier_services/1.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("carrier_service.json")))

carrier, err := client.CarrierService.Update(CarrierService{Id: 1})
carrier, err := client.CarrierService.Update(context.Background(), CarrierService{Id: 1})
if err != nil {
t.Errorf("Carrier.Update returned error: %v", err)
}
Expand All @@ -125,7 +126,7 @@ func TestCarrierDelete(t *testing.T) {
httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/carrier_services/1.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{}`))

err := client.CarrierService.Delete(1)
err := client.CarrierService.Delete(context.Background(), 1)
if err != nil {
t.Errorf("Carrier.Delete returned error: %v", err)
}
Expand Down
14 changes: 7 additions & 7 deletions collect_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package goshopify

import (
"context"
"fmt"
"reflect"
"testing"
Expand All @@ -9,7 +10,6 @@ import (
)

func collectTests(t *testing.T, collect Collect) {

// Test a few fields
cases := []struct {
field string
Expand Down Expand Up @@ -37,7 +37,7 @@ func TestCollectList(t *testing.T) {
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collects.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"collects": [{"id":1},{"id":2}]}`))

collects, err := client.Collect.List(nil)
collects, err := client.Collect.List(context.Background(), nil)
if err != nil {
t.Errorf("Collect.List returned error: %v", err)
}
Expand All @@ -61,7 +61,7 @@ func TestCollectCount(t *testing.T) {
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Collect.Count(nil)
cnt, err := client.Collect.Count(context.Background(), nil)
if err != nil {
t.Errorf("Collect.Count returned error: %v", err)
}
Expand All @@ -71,7 +71,7 @@ func TestCollectCount(t *testing.T) {
t.Errorf("Collect.Count returned %d, expected %d", cnt, expected)
}

cnt, err = client.Collect.Count(ListOptions{SinceID: 123})
cnt, err = client.Collect.Count(context.Background(), ListOptions{SinceID: 123})
if err != nil {
t.Errorf("Collect.Count returned error: %v", err)
}
Expand All @@ -89,7 +89,7 @@ func TestCollectGet(t *testing.T) {
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collects/1.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"collect": {"id":1}}`))

product, err := client.Collect.Get(1, nil)
product, err := client.Collect.Get(context.Background(), 1, nil)
if err != nil {
t.Errorf("Collect.Get returned error: %v", err)
}
Expand All @@ -112,7 +112,7 @@ func TestCollectCreate(t *testing.T) {
ProductID: 6654094787,
}

returnedCollect, err := client.Collect.Create(collect)
returnedCollect, err := client.Collect.Create(context.Background(), collect)
if err != nil {
t.Errorf("Collect.Create returned error: %v", err)
}
Expand All @@ -127,7 +127,7 @@ func TestCollectDelete(t *testing.T) {
httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/collects/1.json", client.pathPrefix),
httpmock.NewStringResponder(200, "{}"))

err := client.Collect.Delete(1)
err := client.Collect.Delete(context.Background(), 1)
if err != nil {
t.Errorf("Collect.Delete returned error: %v", err)
}
Expand Down
15 changes: 9 additions & 6 deletions collection_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package goshopify

import (
"context"
"fmt"
"net/http"
"reflect"
Expand Down Expand Up @@ -38,7 +39,7 @@ func TestCollectionGet(t *testing.T) {
}
}`))

collection, err := client.Collection.Get(1, nil)
collection, err := client.Collection.Get(context.Background(), 1, nil)
if err != nil {
t.Errorf("Collection.Get returned error: %v", err)
}
Expand Down Expand Up @@ -121,7 +122,7 @@ func TestCollectionListProducts(t *testing.T) {
]
}`))

products, err := client.Collection.ListProducts(1, nil)
products, err := client.Collection.ListProducts(context.Background(), 1, nil)
if err != nil {
t.Errorf("Collection.ListProducts returned error: %v", err)
}
Expand Down Expand Up @@ -176,6 +177,7 @@ func TestCollectionListProducts(t *testing.T) {
t.Errorf("Collection.ListProducts returned %+v, expected %+v", products, expected)
}
}

func TestCollectionListProductsError(t *testing.T) {
setup()
defer teardown()
Expand All @@ -188,7 +190,7 @@ func TestCollectionListProductsError(t *testing.T) {
some invalid json
}`))

products, err := client.Collection.ListProducts(1, nil)
products, err := client.Collection.ListProducts(context.Background(), 1, nil)

if len(products) > 0 {
t.Errorf("Collection.ListProducts returned products %v, expected no products to be returned", products)
Expand All @@ -199,6 +201,7 @@ func TestCollectionListProductsError(t *testing.T) {
t.Errorf("Collection.ListProducts err returned %v, expected %v", err, expectedError)
}
}

func TestListProductsWithPagination(t *testing.T) {
setup()
defer teardown()
Expand Down Expand Up @@ -256,7 +259,7 @@ func TestListProductsWithPagination(t *testing.T) {
},
}))

products, page, err := client.Collection.ListProductsWithPagination(1, nil)
products, page, err := client.Collection.ListProductsWithPagination(context.Background(), 1, nil)
if err != nil {
t.Errorf("Collection.ListProductsWithPagination returned error: %v", err)
}
Expand Down Expand Up @@ -345,7 +348,7 @@ func TestCollectionListProductsWithPaginationRequestError(t *testing.T) {
some invalid json
}`))

products, pagination, err := client.Collection.ListProductsWithPagination(1, nil)
products, pagination, err := client.Collection.ListProductsWithPagination(context.Background(), 1, nil)

if len(products) > 0 {
t.Errorf("Collection.ListProductsWithPagination returned products %v, expected no products to be returned", products)
Expand Down Expand Up @@ -376,7 +379,7 @@ func TestCollectionListProductsWithPaginationExtractionError(t *testing.T) {
},
}))

products, pagination, err := client.Collection.ListProductsWithPagination(1, nil)
products, pagination, err := client.Collection.ListProductsWithPagination(context.Background(), 1, nil)
if len(products) > 0 {
t.Errorf("Collection.ListProductsWithPagination returned products %v, expected no products to be returned", products)
}
Expand Down
30 changes: 15 additions & 15 deletions customcollection_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package goshopify

import (
"context"
"fmt"
"reflect"
"testing"
Expand All @@ -10,7 +11,6 @@ import (
)

func customCollectionTests(t *testing.T, collection CustomCollection) {

// Test a few fields
cases := []struct {
field string
Expand Down Expand Up @@ -38,7 +38,7 @@ func TestCustomCollectionList(t *testing.T) {
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"custom_collections": [{"id":1},{"id":2}]}`))

products, err := client.CustomCollection.List(nil)
products, err := client.CustomCollection.List(context.Background(), nil)
if err != nil {
t.Errorf("CustomCollection.List returned error: %v", err)
}
Expand All @@ -63,7 +63,7 @@ func TestCustomCollectionCount(t *testing.T) {
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.CustomCollection.Count(nil)
cnt, err := client.CustomCollection.Count(context.Background(), nil)
if err != nil {
t.Errorf("CustomCollection.Count returned error: %v", err)
}
Expand All @@ -74,7 +74,7 @@ func TestCustomCollectionCount(t *testing.T) {
}

date := time.Date(2016, time.January, 1, 0, 0, 0, 0, time.UTC)
cnt, err = client.CustomCollection.Count(CountOptions{CreatedAtMin: date})
cnt, err = client.CustomCollection.Count(context.Background(), CountOptions{CreatedAtMin: date})
if err != nil {
t.Errorf("CustomCollection.Count returned error: %v", err)
}
Expand All @@ -92,7 +92,7 @@ func TestCustomCollectionGet(t *testing.T) {
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections/1.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"custom_collection": {"id":1}}`))

product, err := client.CustomCollection.Get(1, nil)
product, err := client.CustomCollection.Get(context.Background(), 1, nil)
if err != nil {
t.Errorf("CustomCollection.Get returned error: %v", err)
}
Expand All @@ -114,7 +114,7 @@ func TestCustomCollectionCreate(t *testing.T) {
Title: "Macbooks",
}

returnedCollection, err := client.CustomCollection.Create(collection)
returnedCollection, err := client.CustomCollection.Create(context.Background(), collection)
if err != nil {
t.Errorf("CustomCollection.Create returned error: %v", err)
}
Expand All @@ -134,7 +134,7 @@ func TestCustomCollectionUpdate(t *testing.T) {
Title: "Macbooks",
}

returnedCollection, err := client.CustomCollection.Update(collection)
returnedCollection, err := client.CustomCollection.Update(context.Background(), collection)
if err != nil {
t.Errorf("CustomCollection.Update returned error: %v", err)
}
Expand All @@ -149,7 +149,7 @@ func TestCustomCollectionDelete(t *testing.T) {
httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections/1.json", client.pathPrefix),
httpmock.NewStringResponder(200, "{}"))

err := client.CustomCollection.Delete(1)
err := client.CustomCollection.Delete(context.Background(), 1)
if err != nil {
t.Errorf("CustomCollection.Delete returned error: %v", err)
}
Expand All @@ -162,7 +162,7 @@ func TestCustomCollectionListMetafields(t *testing.T) {
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`))

metafields, err := client.CustomCollection.ListMetafields(1, nil)
metafields, err := client.CustomCollection.ListMetafields(context.Background(), 1, nil)
if err != nil {
t.Errorf("CustomCollection.ListMetafields() returned error: %v", err)
}
Expand All @@ -187,7 +187,7 @@ func TestCustomCollectionCountMetafields(t *testing.T) {
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.CustomCollection.CountMetafields(1, nil)
cnt, err := client.CustomCollection.CountMetafields(context.Background(), 1, nil)
if err != nil {
t.Errorf("CustomCollection.CountMetafields() returned error: %v", err)
}
Expand All @@ -198,7 +198,7 @@ func TestCustomCollectionCountMetafields(t *testing.T) {
}

date := time.Date(2016, time.January, 1, 0, 0, 0, 0, time.UTC)
cnt, err = client.CustomCollection.CountMetafields(1, CountOptions{CreatedAtMin: date})
cnt, err = client.CustomCollection.CountMetafields(context.Background(), 1, CountOptions{CreatedAtMin: date})
if err != nil {
t.Errorf("CustomCollection.CountMetafields() returned error: %v", err)
}
Expand All @@ -216,7 +216,7 @@ func TestCustomCollectionGetMetafield(t *testing.T) {
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/2.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"metafield": {"id":2}}`))

metafield, err := client.CustomCollection.GetMetafield(1, 2, nil)
metafield, err := client.CustomCollection.GetMetafield(context.Background(), 1, 2, nil)
if err != nil {
t.Errorf("CustomCollection.GetMetafield() returned error: %v", err)
}
Expand All @@ -241,7 +241,7 @@ func TestCustomCollectionCreateMetafield(t *testing.T) {
Namespace: "affiliates",
}

returnedMetafield, err := client.CustomCollection.CreateMetafield(1, metafield)
returnedMetafield, err := client.CustomCollection.CreateMetafield(context.Background(), 1, metafield)
if err != nil {
t.Errorf("CustomCollection.CreateMetafield() returned error: %v", err)
}
Expand All @@ -264,7 +264,7 @@ func TestCustomCollectionUpdateMetafield(t *testing.T) {
Namespace: "affiliates",
}

returnedMetafield, err := client.CustomCollection.UpdateMetafield(1, metafield)
returnedMetafield, err := client.CustomCollection.UpdateMetafield(context.Background(), 1, metafield)
if err != nil {
t.Errorf("CustomCollection.UpdateMetafield() returned error: %v", err)
}
Expand All @@ -279,7 +279,7 @@ func TestCustomCollectionDeleteMetafield(t *testing.T) {
httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/2.json", client.pathPrefix),
httpmock.NewStringResponder(200, "{}"))

err := client.CustomCollection.DeleteMetafield(1, 2)
err := client.CustomCollection.DeleteMetafield(context.Background(), 1, 2)
if err != nil {
t.Errorf("CustomCollection.DeleteMetafield() returned error: %v", err)
}
Expand Down
Loading

0 comments on commit 043b90b

Please sign in to comment.