forked from seborama/govcr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgovcr_example1_test.go
44 lines (34 loc) · 1.18 KB
/
govcr_example1_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package govcr_test
import (
"fmt"
"io/ioutil"
"strings"
"github.com/seborama/govcr"
)
const example1CassetteName = "MyCassette1"
func runTestEx1() {
// Create vcr and make http call
vcr := govcr.NewVCR(example1CassetteName, nil)
resp, _ := vcr.Client.Get("http://www.example.com/foo")
// Show results
fmt.Printf("%d ", resp.StatusCode)
fmt.Printf("%s ", resp.Header.Get("Content-Type"))
body, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
fmt.Printf("%v ", strings.Contains(string(body), "domain in examples without prior coordination or asking for permission."))
fmt.Printf("%+v\n", vcr.Stats())
}
// Example_simpleVCR is an example use of govcr.
// It shows how to use govcr in the simplest case when the default
// http.Client suffices.
func Example_number1SimpleVCR() {
// Delete cassette to enable live HTTP call
govcr.DeleteCassette(example1CassetteName, "")
// 1st run of the test - will use live HTTP calls
runTestEx1()
// 2nd run of the test - will use playback
runTestEx1()
// Output:
// 404 text/html; charset=UTF-8 true {TracksLoaded:0 TracksRecorded:1 TracksPlayed:0}
// 404 text/html; charset=UTF-8 true {TracksLoaded:1 TracksRecorded:0 TracksPlayed:1}
}