Skip to content

Commit

Permalink
Merge branch 'klauspost-add-remove-tls-option'
Browse files Browse the repository at this point in the history
  • Loading branch information
seborama committed Jan 3, 2019
2 parents 2adb223 + 779b8e4 commit a3489bf
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cassette.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ type cassette struct {
Tracks []track

// stats is not exported since it doesn't need serialising
stats Stats
stats Stats
removeTLS bool
}

func (k7 *cassette) isLongPlay() bool {
Expand Down Expand Up @@ -286,6 +287,9 @@ func (k7 *cassette) gunzipFilter(data []byte) ([]byte, error) {

// addTrack adds a track to a cassette.
func (k7 *cassette) addTrack(track *track) {
if k7.removeTLS {
track.Response.TLS = nil
}
k7.Tracks = append(k7.Tracks, *track)
}

Expand Down
85 changes: 85 additions & 0 deletions cassette_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package govcr

import (
"bytes"
"crypto/tls"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -202,3 +203,87 @@ func Test_cassetteNameToFilename(t *testing.T) {
})
}
}

func Test_cassette_addTrack(t *testing.T) {
type fields struct {
removeTLS bool
}
type args struct {
track track
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "with tls, keep",
fields: fields{
removeTLS: false,
},
args: args{
track: track{
Response: response{
TLS: &tls.ConnectionState{},
},
},
},
},
{
name: "with tls, remove",
fields: fields{
removeTLS: true,
},
args: args{
track: track{
Response: response{
TLS: &tls.ConnectionState{},
},
},
},
},
{
name: "without tls, keep",
fields: fields{
removeTLS: false,
},
args: args{
track: track{
Response: response{
TLS: nil,
},
},
},
},
{
name: "without tls, remove",
fields: fields{
removeTLS: true,
},
args: args{
track: track{
Response: response{
TLS: nil,
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
k7 := &cassette{
Name: tt.name,
Path: tt.name,
removeTLS: tt.fields.removeTLS,
}
k7.addTrack(&tt.args.track)
gotTLS := k7.Tracks[0].Response.TLS != nil
if gotTLS && tt.fields.removeTLS {
t.Errorf("got TLS, but it should have been removed")
}
if !gotTLS && !tt.fields.removeTLS && tt.args.track.Response.TLS != nil {
t.Errorf("tls was removed, but shouldn't")
}
})
}
}
5 changes: 5 additions & 0 deletions govcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type VCRConfig struct {
DisableRecording bool
Logging bool
CassettePath string

// RemoveTLS will remove TLS from the Response when recording.
// TLS information is rarely needed and takes up a lot of space.
RemoveTLS bool
}

// PCB stands for Printed Circuit Board. It is a structure that holds some
Expand Down Expand Up @@ -170,6 +174,7 @@ func NewVCR(cassetteName string, vcrConfig *VCRConfig) *VCRControlPanel {
if err != nil {
logger.Fatal(err)
}
cassette.removeTLS = vcrConfig.RemoveTLS

// create PCB
pcbr := &pcb{
Expand Down

0 comments on commit a3489bf

Please sign in to comment.