INNER CODE UNIT · Go

TestCRUDWithContext

dikhan/terraform-provider-openapi · openapi/common_test.go:20

func TestCRUDWithContext(t *testing.T) {
	Convey("Given a create function (which returns successfully), a create timeout and a resource name", t, func() {
		stubCreateFunction := func(data *schema.ResourceData, i interface{}) error {
			return nil // this means the function returned successfully
		}
		createTimeout := 1 * time.Second
		resourceName := "cdn_v1"
		Convey("When crudWithContext is called", func() {
			contextAwareFunc := crudWithContext(stubCreateFunction, schema.TimeoutCreate, resourceName)
			Convey("Then the returned function which is context aware should not timeout and return an empty diagnosis", func() {
				ctx := context.Background()
				ctx, cancel := context.WithTimeout(ctx, createTimeout)
				defer cancel()
				diagnosis := contextAwareFunc(ctx, &schema.ResourceData{}, nil)
				So(diagnosis, ShouldBeEmpty)
			})
		})
	})

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…