Skip to content

Commit

Permalink
BREAKING CHANGE: rename CassetteMaker, WithCassetteCrypto*, WithCasse…
Browse files Browse the repository at this point in the history
…tteCrypter* (#97)

BREAKING CHANGE: rename CassetteMaker to CassetteLoader
BREAKING CHANGE: Rename WithCassetteCrypto* to WithCipher
BREAKING CHANGE: Rename WithCassetteCrypter to WithCrypter
ci: Update linter config
  • Loading branch information
seborama authored Aug 25, 2022
1 parent a3e95c2 commit 081f5b6
Show file tree
Hide file tree
Showing 30 changed files with 113 additions and 123 deletions.
8 changes: 0 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,6 @@ linters-settings:
# Default: false
check-exported: true

varcheck:
# Check usage of exported fields and variables.
# Default: false
exported-fields: true

linters:
# Disable all linters.
# Default: false
Expand All @@ -634,7 +629,6 @@ linters:
- containedctx
- contextcheck
- cyclop
- deadcode
# - decorder
# - depguard
- dogsled
Expand Down Expand Up @@ -695,7 +689,6 @@ linters:
#- scopelint
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- tagliatelle
- tenv
Expand All @@ -706,7 +699,6 @@ linters:
- unconvert
- unparam
- unused
- varcheck
# - varnamelen
# - wastedassign
# - whitespace
Expand Down
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<img src="https://github.com/seborama/govcr/actions/workflows/codeql-analysis.yml/badge.svg?branch=master" alt="govcr">
</a>

<a href="https://pkg.go.dev/github.com/seborama/govcr/v10">
<a href="https://pkg.go.dev/github.com/seborama/govcr/v11">
<img src="https://img.shields.io/badge/godoc-reference-blue.svg" alt="govcr">
</a>

<a href="https://goreportcard.com/report/github.com/seborama/govcr/v10">
<img src="https://goreportcard.com/badge/github.com/seborama/govcr/v10" alt="govcr">
<a href="https://goreportcard.com/report/github.com/seborama/govcr/v11">
<img src="https://goreportcard.com/badge/github.com/seborama/govcr/v11" alt="govcr">
</a>
</p>

Expand Down Expand Up @@ -77,7 +77,7 @@ This project is an adaptation for Google's Go / Golang programming language.

func TestExample1() {
vcr := govcr.NewVCR(
govcr.NewCassetteMaker("MyCassette1.json"),
govcr.NewCassetteLoader("MyCassette1.json"),
govcr.WithRequestMatcher(govcr.NewMethodURLRequestMatcher()), // use a "relaxed" request matcher
)

Expand All @@ -98,15 +98,15 @@ We use a "relaxed" request matcher because `example.com` injects an "`Age`" head
## Install

```bash
go get github.com/seborama/govcr/v10@latest
go get github.com/seborama/govcr/v11@latest
```

For all available releases, please check the [releases](https://github.com/seborama/govcr/releases) tab on github.

And your source code would use this import:

```go
import "github.com/seborama/govcr/v10"
import "github.com/seborama/govcr/v11"
```

For versions of **govcr** before v5 (which don't use go.mod), use a dependency manager to lock the version you wish to use (perhaps v4)!
Expand Down Expand Up @@ -136,7 +136,7 @@ go get gopkg.in/seborama/govcr.v4

**govcr** is a wrapper around the Go `http.Client`. It can record live HTTP traffic to files (called "**cassettes**") and later replay HTTP requests ("**tracks**") from them instead of live HTTP calls.

The code documentation can be found on [godoc](https://pkg.go.dev/github.com/seborama/govcr/v10).
The code documentation can be found on [godoc](https://pkg.go.dev/github.com/seborama/govcr/v11).

When using **govcr**'s `http.Client`, the request is matched against the **tracks** on the '**cassette**':

Expand Down Expand Up @@ -286,7 +286,7 @@ func TestExample2() {

// Instantiate VCR.
vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName2),
govcr.NewCassetteLoader(exampleCassetteName2),
govcr.WithClient(app.httpClient),
)

Expand All @@ -309,7 +309,7 @@ Remove Response.TLS from the cassette **recording**:

```go
vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName2),
govcr.NewCassetteLoader(exampleCassetteName2),
govcr.WithTrackRecordingMutators(track.ResponseDeleteTLS()),
// ^^^^^^^^^
)
Expand All @@ -322,7 +322,7 @@ Remove Response.TLS from the track at **playback** time:

```go
vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName2),
govcr.NewCassetteLoader(exampleCassetteName2),
govcr.WithTrackReplayingMutators(track.ResponseDeleteTLS()),
// ^^^^^^^^^
)
Expand All @@ -346,7 +346,7 @@ vcr.AddReplayingMutators(track.ResponseDeleteTLS())

```go
vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName2),
govcr.NewCassetteLoader(exampleCassetteName2),
// Normal mode is default, no special option required :)
)
// or equally:
Expand All @@ -357,7 +357,7 @@ vcr.SetNormalMode()

```go
vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName2),
govcr.NewCassetteLoader(exampleCassetteName2),
govcr.WithLiveOnlyMode(),
)
// or equally:
Expand All @@ -368,7 +368,7 @@ vcr.SetLiveOnlyMode()

```go
vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName2),
govcr.NewCassetteLoader(exampleCassetteName2),
govcr.WithReadOnlyMode(),
)
// or equally:
Expand All @@ -379,7 +379,7 @@ vcr.SetReadOnlyMode(true) // `false` to disable option

```go
vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName2),
govcr.NewCassetteLoader(exampleCassetteName2),
govcr.WithOfflineMode(),
)
// or equally:
Expand All @@ -396,11 +396,10 @@ At time of creating a new VCR with **govcr**:
// See TestExample4 in tests for fully working example.

vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName4).
WithCassetteCrypto(
govcr.NewCassetteLoader(exampleCassetteName4).
WithCipher(
encryption.NewChaCha20Poly1305WithRandomNonceGenerator,
"test-fixtures/TestExample4.unsafe.key",
),
"test-fixtures/TestExample4.unsafe.key"),
)
```

Expand All @@ -410,7 +409,7 @@ Or, at time of loading a cassette from the `ControlPanel`:
// See TestExample4 in tests for fully working example.
err := vcr.LoadCassette(
exampleCassetteName4,
govcr.WithCassetteCrypto(
govcr.WithCipher(
encryption.NewChaCha20Poly1305WithRandomNonceGenerator,
"test-fixtures/TestExample4.unsafe.key"),
)
Expand All @@ -436,12 +435,11 @@ func (ng myNonceGenerator) Generate() ([]byte, error) {
}

vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName4).
WithCassetteCryptoCustomNonce(
govcr.NewCassetteLoader(exampleCassetteName4).
WithCipherCustomNonce(
encryption.NewChaCha20Poly1305,
"test-fixtures/TestExample4.unsafe.key",
nonceGenerator,
),
nonceGenerator),
)
```

Expand All @@ -454,7 +452,7 @@ vcr := govcr.NewVCR(
The command is located in the `cmd/govcr` folder, to install it:

```bash
go install github.com/seborama/govcr/v10/cmd/govcr@latest
go install github.com/seborama/govcr/v11/cmd/govcr@latest
```

Example usage:
Expand Down Expand Up @@ -517,7 +515,7 @@ How you specifically tackle this in practice really depends on how the API you a
func TestExample3(t *testing.T) {
// Instantiate VCR.
vcr := govcr.NewVCR(
govcr.NewCassetteMaker(exampleCassetteName3),
govcr.NewCassetteLoader(exampleCassetteName3),
govcr.WithRequestMatcher(
govcr.NewBlankRequestMatcher(
govcr.WithRequestMatcherFunc(
Expand Down
14 changes: 7 additions & 7 deletions cassette/cassette.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"github.com/google/uuid"
"github.com/pkg/errors"

"github.com/seborama/govcr/v10/cassette/track"
"github.com/seborama/govcr/v10/compression"
cryptoerr "github.com/seborama/govcr/v10/encryption/errors"
govcrerr "github.com/seborama/govcr/v10/errors"
"github.com/seborama/govcr/v10/stats"
"github.com/seborama/govcr/v11/cassette/track"
"github.com/seborama/govcr/v11/compression"
cryptoerr "github.com/seborama/govcr/v11/encryption/errors"
govcrerr "github.com/seborama/govcr/v11/errors"
"github.com/seborama/govcr/v11/stats"
)

// Cassette contains a set of tracks.
Expand Down Expand Up @@ -48,8 +48,8 @@ type Crypter interface {
// to create a new Cassette.
type Option func(*Cassette)

// WithCassetteCrypter provides a crypter to encrypt/decrypt cassette content.
func WithCassetteCrypter(crypter Crypter) Option {
// WithCrypter provides a crypter to encrypt/decrypt cassette content.
func WithCrypter(crypter Crypter) Option {
return func(k7 *Cassette) {
if k7.crypter != nil {
log.Println("notice: setting a crypter but another one had already been registered - this is incorrect usage")
Expand Down
14 changes: 7 additions & 7 deletions cassette/cassette_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v10/cassette"
"github.com/seborama/govcr/v10/cassette/track"
"github.com/seborama/govcr/v10/encryption"
"github.com/seborama/govcr/v11/cassette"
"github.com/seborama/govcr/v11/cassette/track"
"github.com/seborama/govcr/v11/encryption"
)

func Test_cassette_GzipFilter(t *testing.T) {
Expand Down Expand Up @@ -132,7 +132,7 @@ func Test_cassette_Encryption(t *testing.T) {
c, err := encryption.NewAESGCMWithRandomNonceGenerator(key)
require.NoError(t, err)

k7 := cassette.NewCassette(cassetteName, cassette.WithCassetteCrypter(c))
k7 := cassette.NewCassette(cassetteName, cassette.WithCrypter(c))

trk := &track.Track{}

Expand All @@ -142,7 +142,7 @@ func Test_cassette_Encryption(t *testing.T) {
// STEP 2: ensure cassette loads.
var k8 *cassette.Cassette
require.NotPanics(t, func() {
k8 = cassette.LoadCassette(cassetteName, cassette.WithCassetteCrypter(c))
k8 = cassette.LoadCassette(cassetteName, cassette.WithCrypter(c))
})

// STEP 3: perform high and low-level validation checks on cassette file.
Expand Down Expand Up @@ -187,7 +187,7 @@ func Test_cassette_CanEncryptPlainCassette(t *testing.T) {
c, err := encryption.NewAESGCMWithRandomNonceGenerator(key)
require.NoError(t, err)

k7 = cassette.LoadCassette(cassetteName, cassette.WithCassetteCrypter(c))
k7 = cassette.LoadCassette(cassetteName, cassette.WithCrypter(c))

trk = &track.Track{UUID: "trk-2"}

Expand All @@ -197,7 +197,7 @@ func Test_cassette_CanEncryptPlainCassette(t *testing.T) {
// STEP 2: ensure cassette loads.
var k8 *cassette.Cassette
require.NotPanics(t, func() {
k8 = cassette.LoadCassette(cassetteName, cassette.WithCassetteCrypter(c))
k8 = cassette.LoadCassette(cassetteName, cassette.WithCrypter(c))
})

// STEP 3: perform high and low-level validation checks on cassette file.
Expand Down
2 changes: 1 addition & 1 deletion cassette/cassette_wb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/seborama/govcr/v10/stats"
"github.com/seborama/govcr/v11/stats"
)

func Test_cassette_NumberOfTracks_PanicsWhenNoCassette(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cassette/track/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v10/cassette/track"
"github.com/seborama/govcr/v11/cassette/track"
)

func TestRequest_Clone(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cassette/track/mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v10/cassette/track"
"github.com/seborama/govcr/v11/cassette/track"
)

func Test_Mutator_On(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cassette/track/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/pkg/errors"

trkerr "github.com/seborama/govcr/v10/cassette/track/errors"
trkerr "github.com/seborama/govcr/v11/cassette/track/errors"
)

// Track is a recording (HTTP Request + Response) in a cassette.
Expand Down
4 changes: 2 additions & 2 deletions cmd/govcr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/pkg/errors"

"github.com/seborama/govcr/v10/cassette"
"github.com/seborama/govcr/v10/encryption"
"github.com/seborama/govcr/v11/cassette"
"github.com/seborama/govcr/v11/encryption"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/pkg/errors"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v10"
"github.com/seborama/govcr/v10/stats"
"github.com/seborama/govcr/v11"
"github.com/seborama/govcr/v11/stats"
)

func TestConcurrencySafety(t *testing.T) {
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestConcurrencySafety(t *testing.T) {

func createVCR(cassetteName string, client *http.Client) *govcr.ControlPanel {
return govcr.NewVCR(
govcr.NewCassetteMaker(cassetteName),
govcr.NewCassetteLoader(cassetteName),
govcr.WithClient(client))
}

Expand Down
4 changes: 2 additions & 2 deletions controlpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package govcr
import (
"net/http"

"github.com/seborama/govcr/v10/cassette/track"
"github.com/seborama/govcr/v10/stats"
"github.com/seborama/govcr/v11/cassette/track"
"github.com/seborama/govcr/v11/stats"
)

// ControlPanel holds the parts of a VCR that can be interacted with.
Expand Down
2 changes: 1 addition & 1 deletion controlpanel_wb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/seborama/govcr/v10/cassette/track"
"github.com/seborama/govcr/v11/cassette/track"
)

func TestControlPanel_SetRecordingMutators(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion encryption/.study/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"

cryptoerr "github.com/seborama/govcr/v10/encryption/errors"
cryptoerr "github.com/seborama/govcr/v11/encryption/errors"
)

// nolint: deadcode
Expand Down
2 changes: 1 addition & 1 deletion encryption/aesgcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/aes"
"crypto/cipher"

cryptoerr "github.com/seborama/govcr/v10/encryption/errors"
cryptoerr "github.com/seborama/govcr/v11/encryption/errors"
)

// NewAESGCMWithRandomNonceGenerator creates a new Cryptor initialised with an
Expand Down
2 changes: 1 addition & 1 deletion encryption/aesgcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/seborama/govcr/v10/encryption"
"github.com/seborama/govcr/v11/encryption"
)

func TestCryptor_AESGCM(t *testing.T) {
Expand Down
Loading

0 comments on commit 081f5b6

Please sign in to comment.