Repository: gavv/httpexpect (go)

Issue:
Add Environment.Delete
Add a method to delete value from environment by key.

The new method should have documentation comment with code example and be covered by test.

Pull request description:
Add Environment.Delete
closes #235 

Patch:
diff --git a/environment.go b/environment.go
index 8611adf..dd493d7 100644
--- a/environment.go
+++ b/environment.go
@@ -61,6 +61,20 @@ func (e *Environment) Put(key string, value interface{}) {
 	e.data[key] = value
 }
 
+// Delete removes the value with key from the environment.
+//
+// Example:
+//
+//	env := NewEnvironment(t)
+//	env.Put("key1", "str")
+//	env.Delete("key1")
+func (e *Environment) Delete(key string) {
+	opChain := e.chain.enter("Delete(%q)", key)
+	defer opChain.leave()
+
+	delete(e.data, key)
+}
+
 // Has returns true if value exists in the environment.
 //
 // Example:


Test patch:
diff --git a/chain_test.go b/chain_test.go
index 05096a3..11a7357 100644
--- a/chain_test.go
+++ b/chain_test.go
@@ -295,6 +295,28 @@ func TestChain_Panics(t *testing.T) {
 		})
 	})
 
+	t.Run("set_request_twice", func(t *testing.T) {
+		chain := newChainWithDefaults("test", newMockReporter(t))
+
+		opChain := chain.enter("foo")
+		opChain.setRequest(&Request{})
+
+		assert.Panics(t, func() {
+			opChain.setRequest(&Request{})
+		})
+	})
+
+	t.Run("set_response_twice", func(t *testing.T) {
+		chain := newChainWithDefaults("test", newMockReporter(t))
+
+		opChain := chain.enter("foo")
+		opChain.setResponse(&Response{})
+
+		assert.Panics(t, func() {
+			opChain.setResponse(&Response{})
+		})
+	})
+
 	t.Run("leave_without_enter", func(t *testing.T) {
 		chain := newChainWithDefaults("test", newMockReporter(t))
 
@@ -450,8 +472,10 @@ func TestChain_Panics(t *testing.T) {
 	t.Run("invalid_assertion", func(t *testing.T) {
 		chain := newChainWithDefaults("test", newMockReporter(t))
 
+		opChain := chain.enter("foo")
+
 		assert.Panics(t, func() {
-			chain.fail(AssertionFailure{
+			opChain.fail(AssertionFailure{
 				Type: AssertionType(9999),
 			})
 		})
diff --git a/environment_test.go b/environment_test.go
index abd6b09..a03ae83 100644
--- a/environment_test.go
+++ b/environment_test.go
@@ -53,6 +53,26 @@ func TestEnvironment_Generic(t *testing.T) {
 	env.chain.assertFailed(t)
 }
 
+func TestEnvironment_Delete(t *testing.T) {
+	env := newEnvironment(newMockChain(t))
+
+	env.Put("good_key", 123)
+	env.chain.assertNotFailed(t)
+
+	assert.True(t, env.Has("good_key"))
+	assert.NotNil(t, env.Get("good_key"))
+	assert.Equal(t, 123, env.Get("good_key").(int))
+	env.chain.assertNotFailed(t)
+
+	env.Delete("good_key")
+	env.chain.assertNotFailed(t)
+
+	assert.False(t, env.Has("good_key"))
+	assert.Nil(t, env.Get("good_key"))
+	env.chain.assertFailed(t)
+	env.chain.clearFailed()
+}
+
 func TestEnvironment_NotFound(t *testing.T) {
 	env := newEnvironment(newMockChain(t))
 
diff --git a/printer_test.go b/printer_test.go
index b62116b..4f39d44 100644
--- a/printer_test.go
+++ b/printer_test.go
@@ -2,9 +2,12 @@ package httpexpect
 
 import (
 	"bytes"
+	"errors"
 	"io/ioutil"
 	"net/http"
 	"testing"
+
+	"github.com/stretchr/testify/assert"
 )
 
 func TestPrinter_Compact(t *testing.T) {
@@ -42,3 +45,39 @@ func TestPrinter_Debug(t *testing.T) {
 	printer.Response(&http.Response{}, 0)
 	printer.Response(nil, 0)
 }
+
+type errorReader struct{}
+
+func (errorReader) Read(_ []byte) (n int, err error) {
+	return 0, errors.New("error")
+}
+
+func (errorReader) Close() error {
+	return errors.New("error")
+}
+
+func TestPrinter_Panics(t *testing.T) {
+	t.Run("panic_curl_printer", func(t *testing.T) {
+		curl := NewCurlPrinter(t)
+
+		assert.Panics(t, func() {
+			curl.Request(&http.Request{})
+		})
+	})
+
+	t.Run("panic_debug_printer", func(t *testing.T) {
+		curl := NewDebugPrinter(t, true)
+
+		assert.Panics(t, func() {
+			curl.Request(&http.Request{
+				Body: errorReader{},
+			})
+		})
+
+		assert.Panics(t, func() {
+			curl.Response(&http.Response{
+				Body: errorReader{},
+			}, 0)
+		})
+	})
+}