-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5d492d
commit 60073a1
Showing
2 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package replay | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestNewRequest(t *testing.T) { | ||
t.Run("ValidRequest", func(t *testing.T) { | ||
req, err := newRequest("url", "source") | ||
if err != nil { | ||
t.Fatalf("error got:%q want:nil", err) | ||
} | ||
if req.URL.String() != "url" { | ||
t.Fatalf("got:%s want:url", req.URL.String()) | ||
} | ||
b, err := ioutil.ReadAll(req.Body) | ||
if err != nil { | ||
t.Fatalf("error got:%q want:nil", err) | ||
} | ||
if string(b) != "source" { | ||
t.Fatalf("got:%s want:source", b) | ||
} | ||
}) | ||
|
||
t.Run("InvalidRequest", func(t *testing.T) { | ||
_, err := newRequest("%zzzzz", "source") | ||
if err == nil { | ||
t.Fatalf("error got:nil want:error") | ||
} | ||
}) | ||
} | ||
|
||
func TestHeadersFlag_Set(t *testing.T) { | ||
h := headersFlag{http.Header{}} | ||
t.Run("ValidHeader", func(t *testing.T) { | ||
if err := h.Set("MyHeader:Foo"); err != nil { | ||
t.Fatalf("error got:%q want:nil", err) | ||
} | ||
}) | ||
t.Run("NoValue", func(t *testing.T) { | ||
if err := h.Set("MyHeader"); err == nil { | ||
t.Fatalf("error got:nil want:error") | ||
} | ||
}) | ||
t.Run("KeyValueAsWhitespaces", func(t *testing.T) { | ||
if err := h.Set(" : "); err == nil { | ||
t.Fatalf("error got:nil want:error") | ||
} | ||
}) | ||
} |