diff --git a/.gitignore b/.gitignore index e61714e..75d9b90 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,8 @@ _testmain.go # Ignore test code coverage coverage.txt +vcr.coverprofile +cassette.coverprofile +recorder.coverprofile .idea/ diff --git a/.travis.yml b/.travis.yml index b0e2d01..e8ff3ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ arch: - AMD64 - ppc64le go: + - 1.19 + - 1.18 + - 1.17 + - 1.16 - 1.15 - 1.14 - 1.13 diff --git a/LICENSE b/LICENSE index 9a46132..10547d8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015-2016 Marin Atanasov Nikolov +Copyright (c) 2015-2022 Marin Atanasov Nikolov All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/Makefile b/Makefile index 16153af..046aba6 100644 --- a/Makefile +++ b/Makefile @@ -7,4 +7,4 @@ test: test_cover: ./test_cover.sh -.PHONY: get test +.PHONY: get test test_cover diff --git a/README.md b/README.md index 992a922..f546357 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ and accurate testing of your code. Install `go-vcr` by executing the command below: ```bash -$ go get github.com/dnaeon/go-vcr/v2/recorder +$ go get -v gopkg.in/dnaeon/go-vcr.v2 ``` ## Usage @@ -34,7 +34,7 @@ import ( "log" "time" - "github.com/dnaeon/go-vcr/v2/recorder" + "github.com/dnaeon/go-vcr/recorder" "github.com/coreos/etcd/client" "golang.org/x/net/context" diff --git a/cassette/cassette.go b/cassette/cassette.go index a2a0338..9abc249 100644 --- a/cassette/cassette.go +++ b/cassette/cassette.go @@ -46,7 +46,11 @@ const ( var ( // ErrInteractionNotFound indicates that a requested // interaction was not found in the cassette file - ErrInteractionNotFound = errors.New("Requested interaction not found") + ErrInteractionNotFound = errors.New("requested interaction not found") + + // ErrCassetteNotFound indicates that a requested + // casette doesn't exist (only in Replaying mode) + ErrCassetteNotFound = errors.New("requested cassette not found") ) // Request represents a client request as recorded in the diff --git a/example/fixtures/etcd.yaml b/example/fixtures/etcd.yaml deleted file mode 100644 index 4aac085..0000000 --- a/example/fixtures/etcd.yaml +++ /dev/null @@ -1,59 +0,0 @@ ---- -version: 1 -interactions: -- request: - body: value=bar - form: - value: - - bar - headers: - Content-Type: - - application/x-www-form-urlencoded - url: http://127.0.0.1:2379/v2/keys/foo - method: PUT - response: - body: | - {"action":"set","node":{"key":"/foo","value":"bar","modifiedIndex":4,"createdIndex":4}} - headers: - Content-Length: - - "88" - Content-Type: - - application/json - Date: - - Sat, 13 Feb 2016 11:34:05 GMT - X-Etcd-Cluster-Id: - - 7e27652122e8b2ae - X-Etcd-Index: - - "4" - X-Raft-Index: - - "51" - X-Raft-Term: - - "2" - status: 201 Created - code: 201 -- request: - body: "" - form: {} - headers: {} - url: http://127.0.0.1:2379/v2/keys/foo?quorum=false&recursive=false&sorted=false - method: GET - response: - body: | - {"action":"get","node":{"key":"/foo","value":"bar","modifiedIndex":4,"createdIndex":4}} - headers: - Content-Length: - - "88" - Content-Type: - - application/json - Date: - - Sat, 13 Feb 2016 11:34:05 GMT - X-Etcd-Cluster-Id: - - 7e27652122e8b2ae - X-Etcd-Index: - - "4" - X-Raft-Index: - - "51" - X-Raft-Term: - - "2" - status: 200 OK - code: 200 diff --git a/example/fixtures/golang-org.yaml b/examples/fixtures/golang-org.yaml similarity index 61% rename from example/fixtures/golang-org.yaml rename to examples/fixtures/golang-org.yaml index b01f152..0c3a57f 100644 --- a/example/fixtures/golang-org.yaml +++ b/examples/fixtures/golang-org.yaml @@ -15,16 +15,16 @@ interactions: Content-Type: - text/html Date: - - Mon, 15 Aug 2022 15:20:23 GMT + - Tue, 16 Aug 2022 13:59:35 GMT Location: - https://golang.org/ Server: - Google Frontend X-Cloud-Trace-Context: - - d8d59244088d7f85e5cd6aaffb36abf6 + - 4ce76f3cdf319d88e1d7b34b4ef7f562 status: 302 Found code: 302 - duration: 247.499837ms + duration: 252.761246ms - request: body: "" form: {} @@ -47,7 +47,7 @@ interactions: Content-Type: - text/html; charset=utf-8 Date: - - Mon, 15 Aug 2022 15:20:24 GMT + - Tue, 16 Aug 2022 13:59:35 GMT Location: - https://go.dev/ Server: @@ -55,10 +55,10 @@ interactions: Strict-Transport-Security: - max-age=31536000; includeSubDomains; preload X-Cloud-Trace-Context: - - 5aa4893f9c9a57c5aecc026701935326 + - 1fe9088657d80958a2b4cdc2c2137776 status: 301 Moved Permanently code: 301 - duration: 329.315883ms + duration: 337.125681ms - request: body: "" form: {} @@ -68,7 +68,7 @@ interactions: url: https://go.dev/ method: GET response: - body: "\n\n\n\n\n\n \n\n\n\n\n\n\n \n \n \n\n\n\nThe Go Programming Language\n\n\n\n\n\n\n\n\n\n\n \n\n \n\n\n
\n
\n \n \n
\n
\n\n
\n
\n
\n
\n
\n

Build fast, reliable, and efficient software at scale

\n
    \n
  • \n \n \n \n Go is an open source programming language supported by Google\n
  • \n
  • \n \n \n \n Easy to learn and get started with\n
  • \n
  • \n \n \n \n Built-in concurrency and a robust standard library\n
  • \n
  • \n \n \n \n Growing ecosystem of partners, communities, and tools\n
  • \n
\n
\n \n
\n

\n Download packages for\n Windows 64-bit,\n macOS,\n Linux, and\n more\n

\n

\n The go command by default downloads and authenticates\n modules using the Go module mirror and Go checksum database run by\n Google. Learn more.\n

\n
\n
\n
\n \"Go\n
\n \n
\n
\n
\n
\n

Companies using Go

\n

Organizations in every industry use Go to power their software and services\n \n View all stories\n \n

\n
\n
\n \n
\n
\n
\n
\n
\n
\n
    \n
  • \n
    \n
    \n

    “At the time, no single team member knew Go, but\nwithin a month, everyone was writing in Go and we were\nbuilding out the endpoints. It was the flexibility, how easy it was to use,\nand the really cool concept behind Go (how Go handles native concurrency,\ngarbage collection, and of course safety+speed.) that helped engage us\nduring the build. Also, who can beat that cute mascot!”

    \n
    — Jaime Enrique Garcia Lopez,\n Senior Software Development Manager\n at Capital One\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    \"A small language that compiles fast makes for a happy developer.\nThe Go language is small, compiles really fast, and as a result it lets your\nmind focus on the actual problem and less on the tool you are using to solve\nit. Code, test, debug cycles are so quick that you forget you are not\nworking with an interpreted language. Looking at our code, you see\nless boilerplate and more business logic.\"

    \n
    — Clayton Coleman,\n Lead Engineer, Open Shift\n at RedHat\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    Go has excellent characteristics for scalability and services\nwritten using it typically have very small memory footprints.\nBecause code is compiled into a single static binary, services can also be\ncontainerised with ease, making it much simpler to build and deploy. These\nattributes make Go an ideal choice for companies building\nmicroservices, as you can easily deploy into a highly available and\nscalable environment such as Kubernetes.”

    \n
    — Matt Boyle,\n Lead Software Engineer\n at Curve\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    \"In our tightly managed environments where we run Go code,\nwe have seen a CPU reduction of approximately 10%\nwith cleaner and maintainable code.\"

    \n
    — Bala Natarajan,\n Sr. Director of Engineering, Developer Experience\n at PayPal\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    \"Tooling has always been a problem with our legacy code base... but we have\n found that Go has excellent tooling, plus built-in testing, benchmarking,\n and profiling frameworks. It is easy to write efficient and resilient\n applications. After working on Go, most of our developers don't want\n to go back to other languages.\"

    \n
    — Benjamin Cane,\n Vice President and Principal Engineer\n at American Express\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    \"...when a programming language is designed for exactly the environment most\n of us use right now—scalable, cloud-based servers that are optimized for\n performance—a lot can go right.\"

    \n
    — John Biggs and Ben Popper,\n \n at Stack Overflow\n
    \n
    \n
    \n
  • \n
\n
\n \n \n
\n
\n
\n
\n
\n
\n

Try Go

\n
\n
\n \n
\n
\n
\n
\n
\n \n
\n \n
\n \n Tour\n
\n
\n
\n
\n
\n
\n
\n
\n

What’s possible with Go

\n

\n Use Go for a variety of software development purposes\n

\n
\n \n
\n
\n
\n
\n
\n
\n \n
\n \n \n
\n
\n
\n
\n
\n
\n

Get started with Go

\n

\n Explore a wealth of learning resources, including guided journeys, courses, books, and more.\n

\n \n
\n
\n \n
    \n
  • \n In-Person Trainings\n
  • \n
  • \n \n Ardan Labs\n \n
    \n Offering customized on-site live training classes.\n
    \n
  • \n
  • \n \n Gopher Guides\n \n
    \n Customized In-person, remote, and online training classes. Training for Developers by Developers.\n
    \n
  • \n
  • \n \n Boss Sauce Creative\n \n
    \n Personalized or track-based Go training for teams.\n
    \n
  • \n
  • \n \n Shiju Varghese\n \n
    \n On-site classroom training on Go and consulting on distributed systems architectures, in India.\n
    \n
  • \n
\n
\n
\n
\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + body: "\n\n\n\n\n\n \n\n\n\n\n\n\n \n \n \n\n\n\nThe Go Programming Language\n\n\n\n\n\n\n\n\n\n\n \n\n \n\n\n
\n
\n \n \n
\n
\n\n
\n
\n
\n
\n
\n

Build fast, reliable, and efficient software at scale

\n
    \n
  • \n \n \n \n Go is an open source programming language supported by Google\n
  • \n
  • \n \n \n \n Easy to learn and get started with\n
  • \n
  • \n \n \n \n Built-in concurrency and a robust standard library\n
  • \n
  • \n \n \n \n Growing ecosystem of partners, communities, and tools\n
  • \n
\n
\n \n
\n

\n Download packages for\n Windows 64-bit,\n macOS,\n Linux, and\n more\n

\n

\n The go command by default downloads and authenticates\n modules using the Go module mirror and Go checksum database run by\n Google. Learn more.\n

\n
\n
\n
\n \"Go\n
\n \n
\n
\n
\n
\n

Companies using Go

\n

Organizations in every industry use Go to power their software and services\n \n View all stories\n \n

\n
\n
\n \n
\n
\n
\n
\n
\n
\n
    \n
  • \n
    \n
    \n

    “At the time, no single team member knew Go, but\nwithin a month, everyone was writing in Go and we were\nbuilding out the endpoints. It was the flexibility, how easy it was to use,\nand the really cool concept behind Go (how Go handles native concurrency,\ngarbage collection, and of course safety+speed.) that helped engage us\nduring the build. Also, who can beat that cute mascot!”

    \n
    — Jaime Enrique Garcia Lopez,\n Senior Software Development Manager\n at Capital One\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    \"A small language that compiles fast makes for a happy developer.\nThe Go language is small, compiles really fast, and as a result it lets your\nmind focus on the actual problem and less on the tool you are using to solve\nit. Code, test, debug cycles are so quick that you forget you are not\nworking with an interpreted language. Looking at our code, you see\nless boilerplate and more business logic.\"

    \n
    — Clayton Coleman,\n Lead Engineer, Open Shift\n at RedHat\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    Go has excellent characteristics for scalability and services\nwritten using it typically have very small memory footprints.\nBecause code is compiled into a single static binary, services can also be\ncontainerised with ease, making it much simpler to build and deploy. These\nattributes make Go an ideal choice for companies building\nmicroservices, as you can easily deploy into a highly available and\nscalable environment such as Kubernetes.”

    \n
    — Matt Boyle,\n Lead Software Engineer\n at Curve\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    \"In our tightly managed environments where we run Go code,\nwe have seen a CPU reduction of approximately 10%\nwith cleaner and maintainable code.\"

    \n
    — Bala Natarajan,\n Sr. Director of Engineering, Developer Experience\n at PayPal\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    \"Tooling has always been a problem with our legacy code base... but we have\n found that Go has excellent tooling, plus built-in testing, benchmarking,\n and profiling frameworks. It is easy to write efficient and resilient\n applications. After working on Go, most of our developers don't want\n to go back to other languages.\"

    \n
    — Benjamin Cane,\n Vice President and Principal Engineer\n at American Express\n
    \n
    \n
    \n
  • \n
  • \n
    \n
    \n

    \"...when a programming language is designed for exactly the environment most\n of us use right now—scalable, cloud-based servers that are optimized for\n performance—a lot can go right.\"

    \n
    — John Biggs and Ben Popper,\n \n at Stack Overflow\n
    \n
    \n
    \n
  • \n
\n
\n \n \n
\n
\n
\n
\n
\n
\n

Try Go

\n
\n
\n \n
\n
\n
\n
\n
\n \n
\n \n
\n \n Tour\n
\n
\n
\n
\n
\n
\n
\n
\n

What’s possible with Go

\n

\n Use Go for a variety of software development purposes\n

\n
\n \n
\n
\n
\n
\n
\n
\n \n
\n \n \n
\n
\n
\n
\n
\n
\n

Get started with Go

\n

\n Explore a wealth of learning resources, including guided journeys, courses, books, and more.\n

\n \n
\n
\n \n
    \n
  • \n In-Person Trainings\n
  • \n
  • \n \n Ardan Labs\n \n
    \n Offering customized on-site live training classes.\n
    \n
  • \n
  • \n \n Gopher Guides\n \n
    \n Customized In-person, remote, and online training classes. Training for Developers by Developers.\n
    \n
  • \n
  • \n \n Boss Sauce Creative\n \n
    \n Personalized or track-based Go training for teams.\n
    \n
  • \n
  • \n \n Shiju Varghese\n \n
    \n On-site classroom training on Go and consulting on distributed systems architectures, in India.\n
    \n
  • \n
\n
\n
\n
\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" headers: Cache-Control: - private @@ -77,7 +77,7 @@ interactions: Content-Type: - text/html; charset=utf-8 Date: - - Mon, 15 Aug 2022 15:20:24 GMT + - Tue, 16 Aug 2022 13:59:36 GMT Server: - Google Frontend Strict-Transport-Security: @@ -85,7 +85,7 @@ interactions: Vary: - Accept-Encoding X-Cloud-Trace-Context: - - f6d8f761cbee121c445a69cb9b5ac3c0 + - f7f0326b6daa19c71c58439ba8ed26c3 status: 200 OK code: 200 - duration: 288.631624ms + duration: 320.504906ms diff --git a/example/fixtures/iana-reserved-domains.yaml b/examples/fixtures/iana-reserved-domains.yaml similarity index 100% rename from example/fixtures/iana-reserved-domains.yaml rename to examples/fixtures/iana-reserved-domains.yaml diff --git a/example/https_test.go b/examples/https_test.go similarity index 100% rename from example/https_test.go rename to examples/https_test.go diff --git a/example/simple_test.go b/examples/simple_test.go similarity index 100% rename from example/simple_test.go rename to examples/simple_test.go diff --git a/go.mod b/go.mod index e440e21..1ea7065 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,5 @@ -module github.com/dnaeon/go-vcr +module "gopkg.in/dnaeon/go-vcr.v2" -go 1.15 +go 1.19 -require ( - github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 - github.com/onsi/ginkgo v1.16.4 // indirect - github.com/onsi/gomega v1.13.0 // indirect - gopkg.in/yaml.v3 v3.0.1 -) +require gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index e100906..a62c313 100644 --- a/go.sum +++ b/go.sum @@ -1,100 +1,4 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 h1:8Q0qkMVC/MmWkpIdlvZgcv2o2jrlF6zqVOh7W5YHdMA= -github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= -github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= -github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak= -github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/recorder/go17_nobody.go b/recorder/go17_nobody.go deleted file mode 100644 index 465961a..0000000 --- a/recorder/go17_nobody.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2015-2016 Marin Atanasov Nikolov -// Copyright (c) 2016 David Jack -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer -// in this position and unchanged. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR -// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -// IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// +build !go1.8 - -package recorder - -import ( - "io" -) - -// isNoBody returns true iff r is an http.NoBody. -// http.NoBody didn't exist before Go 1.7, so the version in this file -// always returns false. -func isNoBody(r io.ReadCloser) bool { return false } diff --git a/recorder/go18_nobody.go b/recorder/go18_nobody.go deleted file mode 100644 index 062bbe3..0000000 --- a/recorder/go18_nobody.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2015-2016 Marin Atanasov Nikolov -// Copyright (c) 2016 David Jack -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer -// in this position and unchanged. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR -// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -// IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// +build go1.8 - -package recorder - -import ( - "io" - "net/http" -) - -// isNoBody returns true iff r is an http.NoBody. -func isNoBody(r io.ReadCloser) bool { return r == http.NoBody } diff --git a/recorder/recorder.go b/recorder/recorder.go index 8387048..ebcdc2b 100644 --- a/recorder/recorder.go +++ b/recorder/recorder.go @@ -45,12 +45,28 @@ type Mode int // Recorder states const ( + // ModeRecording specifies that VCR will run in recording mode + // and create new cassettes for each HTTP interaction. ModeRecording Mode = iota + + // ModeReplaying specifies that VCR will *only* replay HTTP + // interactions from previously recorded cassettes. If a + // cassette is missing while running in this mode, the + // cassette.ErrCassetteNotFound error will be returned. ModeReplaying + + // ModeDisabled specifies that VCR will not record new + // interactions and the real HTTP transport will be used + // instead. This mode works as a pass-through. ModeDisabled - // Replay record from cassette or record a new one when a request is not - // present in cassette instead of throwing ErrInteractionNotFound + + // ModeReplayingOrRecording replays previously recorded + // interactions from the cassettes, or updates the cassettes, + // if an HTTP interaction is not found. ModeReplayingOrRecording + + // ModePassthrough is a synonym for ModeDisabled + ModePassthrough = ModeDisabled ) // Recorder represents a type used to record and replay @@ -117,7 +133,7 @@ func requestHandler(r *http.Request, c *cassette.Cassette, mode Mode, realTransp } reqBody := &bytes.Buffer{} - if r.Body != nil && !isNoBody(r.Body) { + if r.Body != nil && r.Body != http.NoBody { // Record the request body so we can add it to the cassette r.Body = ioutil.NopCloser(io.TeeReader(r.Body, reqBody)) } @@ -169,38 +185,46 @@ func requestHandler(r *http.Request, c *cassette.Cassette, mode Mode, realTransp // New creates a new recorder func New(cassetteName string) (*Recorder, error) { // Default mode is "replay" if file exists - return NewAsMode(cassetteName, ModeReplaying, nil) + return NewAsMode(cassetteName, ModeReplayingOrRecording, nil) } // NewAsMode creates a new recorder in the specified mode func NewAsMode(cassetteName string, mode Mode, realTransport http.RoundTripper) (*Recorder, error) { - var c *cassette.Cassette + var r = &Recorder{ + mode: mode, + realTransport: realTransport, + } + + if r.realTransport == nil { + r.realTransport = http.DefaultTransport + } + + // Disabled mode has no cassette + if mode == ModeDisabled { + return r, nil + } + cassetteFile := fmt.Sprintf("%s.yaml", cassetteName) - if mode != ModeDisabled { - // Depending on whether the cassette file exists or not we - // either create a new empty cassette or load from file - if _, err := os.Stat(cassetteFile); os.IsNotExist(err) || mode == ModeRecording { - // Create new cassette and enter in recording mode - c = cassette.New(cassetteName) - mode = ModeRecording - } else { - // Load cassette from file and enter replay mode or replay/record mode - c, err = cassette.Load(cassetteName) - if err != nil { - return nil, err - } + // Check if the cassette exists + if _, err := os.Stat(cassetteFile); os.IsNotExist(err) { + // Replaying mode should fail if no cassette exists + if mode == ModeReplaying { + return nil, cassette.ErrCassetteNotFound } - } - if realTransport == nil { - realTransport = http.DefaultTransport + // Otherwise we are in a recording mode, create new cassette and enter in recording mode + r.cassette = cassette.New(cassetteName) + r.mode = ModeRecording + + return r, nil } - r := &Recorder{ - mode: mode, - cassette: c, - realTransport: realTransport, + // Load cassette from file and enter replay mode or replay/record mode + var err error + r.cassette, err = cassette.Load(cassetteName) + if err != nil { + return nil, err } return r, nil diff --git a/recorder/recorder_test.go b/recorder/recorder_test.go index a1e8de0..93bfdf0 100644 --- a/recorder/recorder_test.go +++ b/recorder/recorder_test.go @@ -106,7 +106,7 @@ func TestRecord(t *testing.T) { } defer r.Stop() - if m := r.Mode(); m != recorder.ModeReplaying { + if m := r.Mode(); m != recorder.ModeReplayingOrRecording { t.Fatalf("Expected replaying mode, got %v", m) } @@ -127,10 +127,19 @@ func TestRecord(t *testing.T) { } } +func TestReplayingModeFailsWithEmptyCassette(t *testing.T) { + _, cassPath, _ := setupTests(t, "replaying_test") + + _, err := recorder.NewAsMode(cassPath, recorder.ModeReplaying, nil) + if err != cassette.ErrCassetteNotFound { + t.Fatalf("expected cassette.ErrCassetteNotFound, got %v", err) + } +} + func TestModeContextTimeout(t *testing.T) { // Record initial requests runID, cassPath, tests := setupTests(t, "record_playback_timeout") - _, serverURL := httpRecorderTest(t, runID, tests, cassPath, recorder.ModeReplaying) + _, serverURL := httpRecorderTest(t, runID, tests, cassPath, recorder.ModeReplayingOrRecording) // Re-run without the actual server r, err := recorder.New(cassPath) @@ -152,7 +161,7 @@ func TestModeContextTimeout(t *testing.T) { func TestModePlaybackMissing(t *testing.T) { // Record initial requests runID, cassPath, tests := setupTests(t, "record_playback_missing_test") - httpRecorderTest(t, runID, tests, cassPath, recorder.ModeReplaying) + httpRecorderTest(t, runID, tests, cassPath, recorder.ModeReplayingOrRecording) // setup same path but a new runID so requests won't match runID = time.Now().Format(time.RFC3339Nano) diff --git a/v2/cassette/cassette.go b/v2/cassette/cassette.go deleted file mode 100644 index 9abc249..0000000 --- a/v2/cassette/cassette.go +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright (c) 2015 Marin Atanasov Nikolov -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer -// in this position and unchanged. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR -// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -// IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package cassette - -import ( - "errors" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "os" - "path/filepath" - "sync" - "time" - - "gopkg.in/yaml.v3" -) - -// Cassette format versions -const ( - cassetteFormatV1 = 1 -) - -var ( - // ErrInteractionNotFound indicates that a requested - // interaction was not found in the cassette file - ErrInteractionNotFound = errors.New("requested interaction not found") - - // ErrCassetteNotFound indicates that a requested - // casette doesn't exist (only in Replaying mode) - ErrCassetteNotFound = errors.New("requested cassette not found") -) - -// Request represents a client request as recorded in the -// cassette file -type Request struct { - // Body of request - Body string `yaml:"body"` - - // Form values - Form url.Values `yaml:"form"` - - // Request headers - Headers http.Header `yaml:"headers"` - - // Request URL - URL string `yaml:"url"` - - // Request method - Method string `yaml:"method"` -} - -// Response represents a server response as recorded in the -// cassette file -type Response struct { - // Body of response - Body string `yaml:"body"` - - // Response headers - Headers http.Header `yaml:"headers"` - - // Response status message - Status string `yaml:"status"` - - // Response status code - Code int `yaml:"code"` - - // Response duration (something like "100ms" or "10s") - Duration time.Duration `yaml:"duration"` - - replayed bool -} - -// Interaction type contains a pair of request/response for a -// single HTTP interaction between a client and a server -type Interaction struct { - Request `yaml:"request"` - Response `yaml:"response"` -} - -// Matcher function returns true when the actual request matches -// a single HTTP interaction's request according to the function's -// own criteria. -type Matcher func(*http.Request, Request) bool - -// DefaultMatcher is used when a custom matcher is not defined -// and compares only the method and URL. -func DefaultMatcher(r *http.Request, i Request) bool { - return r.Method == i.Method && r.URL.String() == i.URL -} - -// Filter function allows modification of an interaction before saving. -type Filter func(*Interaction) error - -// Cassette type -type Cassette struct { - // Name of the cassette - Name string `yaml:"-"` - - // File name of the cassette as written on disk - File string `yaml:"-"` - - // Cassette format version - Version int `yaml:"version"` - - // Mutex to lock accessing Interactions. omitempty is set - // to prevent the mutex appearing in the recorded YAML. - Mu sync.RWMutex `yaml:"mu,omitempty"` - // Interactions between client and server - Interactions []*Interaction `yaml:"interactions"` - // ReplayableInteractions defines whether to allow interactions to be replayed or not - ReplayableInteractions bool `yaml:"-"` - - // Matches actual request with interaction requests. - Matcher Matcher `yaml:"-"` - - // Filters interactions before when they are captured. - Filters []Filter `yaml:"-"` - - // SaveFilters are applied to interactions just before they are saved. - SaveFilters []Filter `yaml:"-"` -} - -// New creates a new empty cassette -func New(name string) *Cassette { - c := &Cassette{ - Name: name, - File: fmt.Sprintf("%s.yaml", name), - Version: cassetteFormatV1, - Interactions: make([]*Interaction, 0), - Matcher: DefaultMatcher, - Filters: make([]Filter, 0), - SaveFilters: make([]Filter, 0), - } - - return c -} - -// Load reads a cassette file from disk -func Load(name string) (*Cassette, error) { - c := New(name) - data, err := ioutil.ReadFile(c.File) - if err != nil { - return nil, err - } - - err = yaml.Unmarshal(data, &c) - - return c, err -} - -// AddInteraction appends a new interaction to the cassette -func (c *Cassette) AddInteraction(i *Interaction) { - c.Mu.Lock() - c.Interactions = append(c.Interactions, i) - c.Mu.Unlock() -} - -// GetInteraction retrieves a recorded request/response interaction -func (c *Cassette) GetInteraction(r *http.Request) (*Interaction, error) { - c.Mu.Lock() - defer c.Mu.Unlock() - for _, i := range c.Interactions { - if (c.ReplayableInteractions || !i.replayed) && c.Matcher(r, i.Request) { - i.replayed = true - return i, nil - } - } - - return nil, ErrInteractionNotFound -} - -// Save writes the cassette data on disk for future re-use -func (c *Cassette) Save() error { - c.Mu.RLock() - defer c.Mu.RUnlock() - // Save cassette file only if there were any interactions made - if len(c.Interactions) == 0 { - return nil - } - - for _, interaction := range c.Interactions { - for _, filter := range c.SaveFilters { - if err := filter(interaction); err != nil { - return err - } - } - } - - // Create directory for cassette if missing - cassetteDir := filepath.Dir(c.File) - if _, err := os.Stat(cassetteDir); os.IsNotExist(err) { - if err = os.MkdirAll(cassetteDir, 0755); err != nil { - return err - } - } - - // Marshal to YAML and save interactions - data, err := yaml.Marshal(c) - if err != nil { - return err - } - - f, err := os.Create(c.File) - if err != nil { - return err - } - - defer f.Close() - - // Honor the YAML structure specification - // http://www.yaml.org/spec/1.2/spec.html#id2760395 - _, err = f.Write([]byte("---\n")) - if err != nil { - return err - } - - _, err = f.Write(data) - if err != nil { - return err - } - - return nil -} diff --git a/v2/go.mod b/v2/go.mod deleted file mode 100644 index 8ee76c9..0000000 --- a/v2/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module github.com/dnaeon/go-vcr/v2 - -go 1.16 - -require ( - github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 // indirect - github.com/onsi/ginkgo v1.16.4 // indirect - github.com/onsi/gomega v1.13.0 // indirect - gopkg.in/yaml.v2 v2.4.0 -) diff --git a/v2/go.sum b/v2/go.sum deleted file mode 100644 index 6a0f6e9..0000000 --- a/v2/go.sum +++ /dev/null @@ -1,84 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E= -github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/v2/recorder/recorder.go b/v2/recorder/recorder.go deleted file mode 100644 index 5d74b9d..0000000 --- a/v2/recorder/recorder.go +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright (c) 2015-2016 Marin Atanasov Nikolov -// Copyright (c) 2016 David Jack -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer -// in this position and unchanged. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR -// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -// IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package recorder - -import ( - "bufio" - "bytes" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/http/httputil" - "os" - "strconv" - "time" - - "github.com/dnaeon/go-vcr/v2/cassette" -) - -// Mode represents recording/playback mode -type Mode int - -// Recorder states -const ( - ModeRecording Mode = iota - ModeReplaying - ModeDisabled - // Replay record from cassette or record a new one when a request is not - // present in cassette instead of throwing ErrInteractionNotFound - ModeReplayingOrRecording -) - -// Recorder represents a type used to record and replay -// client and server interactions -type Recorder struct { - // Operating mode of the recorder - mode Mode - - // Cassette used by the recorder - cassette *cassette.Cassette - - // realTransport is the underlying http.RoundTripper to make real requests - realTransport http.RoundTripper - - // Pass through requests. - Passthroughs []Passthrough - - // SkipRequestLatency if set to true will not simulate the - // latency of the original request. When set to false - // (default) it will block for the period of time taken by the - // original request to simulate the latency between our - // recorder and the remote endpoints. - SkipRequestLatency bool -} - -// Passthrough function allows ignoring certain requests. -type Passthrough func(*http.Request) bool - -// SetTransport can be used to configure the behavior of the 'real' client used in record-mode -func (r *Recorder) SetTransport(t http.RoundTripper) { - r.realTransport = t -} - -// Proxies client requests to their original destination -func requestHandler(r *http.Request, c *cassette.Cassette, mode Mode, realTransport http.RoundTripper) (*cassette.Interaction, error) { - // Return interaction from cassette if in replay mode or replay/record mode - if mode == ModeReplaying || mode == ModeReplayingOrRecording { - if err := r.Context().Err(); err != nil { - return nil, err - } - - if interaction, err := c.GetInteraction(r); mode == ModeReplaying { - return interaction, err - } else if mode == ModeReplayingOrRecording && err == nil { - return interaction, err - } - } - - // Copy the original request, so we can read the form values - reqBytes, err := httputil.DumpRequestOut(r, true) - if err != nil { - return nil, err - } - - reqBuffer := bytes.NewBuffer(reqBytes) - copiedReq, err := http.ReadRequest(bufio.NewReader(reqBuffer)) - if err != nil { - return nil, err - } - - err = copiedReq.ParseForm() - if err != nil { - return nil, err - } - - reqBody := &bytes.Buffer{} - if r.Body != nil && r.Body != http.NoBody { - // Record the request body so we can add it to the cassette - r.Body = ioutil.NopCloser(io.TeeReader(r.Body, reqBody)) - } - - // Perform client request to it's original - // destination and record interactions - var start time.Time - start = time.Now() - resp, err := realTransport.RoundTrip(r) - if err != nil { - return nil, err - } - requestDuration := time.Since(start) - defer resp.Body.Close() - - respBody, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - // Add interaction to cassette - interaction := &cassette.Interaction{ - Request: cassette.Request{ - Body: reqBody.String(), - Form: copiedReq.PostForm, - Headers: r.Header, - URL: r.URL.String(), - Method: r.Method, - }, - Response: cassette.Response{ - Body: string(respBody), - Headers: resp.Header, - Status: resp.Status, - Code: resp.StatusCode, - Duration: requestDuration, - }, - } - for _, filter := range c.Filters { - err = filter(interaction) - if err != nil { - return nil, err - } - } - c.AddInteraction(interaction) - - return interaction, nil -} - -// New creates a new recorder -func New(cassetteName string) (*Recorder, error) { - // Default mode is "replay" if file exists - return NewAsMode(cassetteName, ModeReplaying, nil) -} - -// NewAsMode creates a new recorder in the specified mode -func NewAsMode(cassetteName string, mode Mode, realTransport http.RoundTripper) (*Recorder, error) { - var r = &Recorder{ - mode: mode, - realTransport: realTransport, - } - - if r.realTransport == nil { - r.realTransport = http.DefaultTransport - } - - // Disabled mode has no cassette - if mode == ModeDisabled { - return r, nil - } - - cassetteFile := fmt.Sprintf("%s.yaml", cassetteName) - - // Check if the cassette exists - if _, err := os.Stat(cassetteFile); os.IsNotExist(err) { - // Replaying mode should fail if no cassette exists - if mode == ModeReplaying { - return nil, cassette.ErrCassetteNotFound - } - - // Otherwise we are in a recording mode, create new cassette and enter in recording mode - r.cassette = cassette.New(cassetteName) - r.mode = ModeRecording - - return r, nil - } - - // Load cassette from file and enter replay mode or replay/record mode - var err error - r.cassette, err = cassette.Load(cassetteName) - if err != nil { - return nil, err - } - - return r, nil -} - -// Stop is used to stop the recorder and save any recorded interactions -func (r *Recorder) Stop() error { - if r.mode == ModeRecording || r.mode == ModeReplayingOrRecording { - if err := r.cassette.Save(); err != nil { - return err - } - } - - return nil -} - -// RoundTrip implements the http.RoundTripper interface -func (r *Recorder) RoundTrip(req *http.Request) (*http.Response, error) { - if r.mode == ModeDisabled { - return r.realTransport.RoundTrip(req) - } - for _, passthrough := range r.Passthroughs { - if passthrough(req) { - return r.realTransport.RoundTrip(req) - } - } - - // Pass cassette and mode to handler, so that interactions can be - // retrieved or recorded depending on the current recorder mode - interaction, err := requestHandler(req, r.cassette, r.mode, r.realTransport) - - if err != nil { - return nil, err - } - - select { - case <-req.Context().Done(): - return nil, req.Context().Err() - default: - buf := bytes.NewBuffer([]byte(interaction.Response.Body)) - // Apply the duration defined in the interaction - if !r.SkipRequestLatency { - <-time.After(interaction.Response.Duration) - } - - contentLength := int64(buf.Len()) - // For HTTP HEAD requests, the ContentLength should be set to the size - // of the body that would have been sent for a GET. - // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13 - if req.Method == "HEAD" { - if hdr := interaction.Response.Headers.Get("Content-Length"); hdr != "" { - cl, err := strconv.ParseInt(hdr, 10, 64) - if err == nil { - contentLength = cl - } - } - } - return &http.Response{ - Status: interaction.Response.Status, - StatusCode: interaction.Response.Code, - Proto: "HTTP/1.0", - ProtoMajor: 1, - ProtoMinor: 0, - Request: req, - Header: interaction.Response.Headers, - Close: true, - ContentLength: contentLength, - Body: ioutil.NopCloser(buf), - }, nil - } -} - -// CancelRequest implements the github.com/coreos/etcd/client.CancelableTransport interface -func (r *Recorder) CancelRequest(req *http.Request) { - type cancelableTransport interface { - CancelRequest(req *http.Request) - } - if ct, ok := r.realTransport.(cancelableTransport); ok { - ct.CancelRequest(req) - } -} - -// SetMatcher sets a function to match requests against recorded HTTP interactions. -func (r *Recorder) SetMatcher(matcher cassette.Matcher) { - if r.cassette != nil { - r.cassette.Matcher = matcher - } -} - -// SetReplayableInteractions defines whether to allow interactions to be replayed or not. -func (r *Recorder) SetReplayableInteractions(replayable bool) { - if r.cassette != nil { - r.cassette.ReplayableInteractions = replayable - } -} - -// AddPassthrough appends a hook to determine if a request should be ignored by the -// recorder. -func (r *Recorder) AddPassthrough(pass Passthrough) { - r.Passthroughs = append(r.Passthroughs, pass) -} - -// AddFilter appends a hook to modify a request before it is recorded. -// -// Filters are useful for filtering out sensitive parameters from the recorded data. -func (r *Recorder) AddFilter(filter cassette.Filter) { - if r.cassette != nil { - r.cassette.Filters = append(r.cassette.Filters, filter) - } -} - -// AddSaveFilter appends a hook to modify a request before it is saved. -// -// This filter is suitable for treating recorded responses to remove sensitive data. Altering responses using a regular -// AddFilter can have unintended consequences on code that is consuming responses. -func (r *Recorder) AddSaveFilter(filter cassette.Filter) { - if r.cassette != nil { - r.cassette.SaveFilters = append(r.cassette.SaveFilters, filter) - } -} - -// Mode returns recorder state -func (r *Recorder) Mode() Mode { - return r.mode -} diff --git a/v2/recorder/recorder_test.go b/v2/recorder/recorder_test.go deleted file mode 100644 index 9bdcbfd..0000000 --- a/v2/recorder/recorder_test.go +++ /dev/null @@ -1,415 +0,0 @@ -// Copyright (c) 2015-2016 Marin Atanasov Nikolov -// Copyright (c) 2016 David Jack -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer -// in this position and unchanged. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR -// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -// IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, -// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package recorder_test - -import ( - "context" - "fmt" - "io" - "io/ioutil" - "net/http" - "net/http/httptest" - "net/url" - "os" - "path" - "strings" - "testing" - "time" - - "bytes" - - "github.com/dnaeon/go-vcr/v2/cassette" - "github.com/dnaeon/go-vcr/v2/recorder" -) - -type recordTest struct { - method string - body string - want string - wantContentLen int -} - -func httpTests(runID string) []recordTest { - return []recordTest{ - { - method: "GET", - want: "GET " + runID + "\n", - wantContentLen: 4 + len(runID) + 1, - }, - { - method: "HEAD", - wantContentLen: 5 + len(runID) + 1, - }, - { - method: "POST", - body: "post body", - want: "POST " + runID + "\npost body", - wantContentLen: 5 + len(runID) + 10, - }, - { - method: "POST", - body: "alt body", - want: "POST " + runID + "\nalt body", - wantContentLen: 5 + len(runID) + 9, - }, - } -} - -func TestRecord(t *testing.T) { - runID, cassPath, tests := setupTests(t, "record_test") - - r, serverURL := httpRecorderTest(t, runID, tests, cassPath, recorder.ModeRecording) - - c, err := cassette.Load(cassPath) - if err != nil { - t.Fatal(err) - } - - if m := r.Mode(); m != recorder.ModeRecording { - t.Fatalf("Expected recording mode, got %v", m) - } - - for i, test := range tests { - body := c.Interactions[i].Request.Body - if body != test.body { - t.Fatalf("got:\t%s\n\twant:\t%s", string(body), string(test.body)) - } - } - - // Re-run without the actual server - r, err = recorder.New(cassPath) - if err != nil { - t.Fatal(err) - } - defer r.Stop() - - if m := r.Mode(); m != recorder.ModeReplaying { - t.Fatalf("Expected replaying mode, got %v", m) - } - - // Use a custom matcher that includes matching on request body - r.SetMatcher(func(r *http.Request, i cassette.Request) bool { - var b bytes.Buffer - if _, err := b.ReadFrom(r.Body); err != nil { - t.Fatalf("unable to read request body: %s", err) - return false - } - r.Body = ioutil.NopCloser(&b) - return cassette.DefaultMatcher(r, i) && (b.String() == "" || b.String() == i.Body) - }) - - t.Log("replaying") - for _, test := range tests { - test.perform(t, serverURL, r) - } -} - -func TestReplayingModeFailsWithEmptyCassette(t *testing.T) { - _, cassPath, _ := setupTests(t, "replaying_test") - - _, err := recorder.NewAsMode(cassPath, recorder.ModeReplaying, nil) - if err != cassette.ErrCassetteNotFound { - t.Fatalf("expected cassette.ErrCassetteNotFound, got %v", err) - } -} - -func TestModeContextTimeout(t *testing.T) { - // Record initial requests - runID, cassPath, tests := setupTests(t, "record_playback_timeout") - _, serverURL := httpRecorderTest(t, runID, tests, cassPath, recorder.ModeReplayingOrRecording) - - // Re-run without the actual server - r, err := recorder.New(cassPath) - if err != nil { - t.Fatal(err) - } - defer r.Stop() - - for _, test := range tests { - ctx, cancelFn := context.WithCancel(context.Background()) - cancelFn() - _, err := test.performReq(t, ctx, serverURL, r) - if err == nil || err == cassette.ErrInteractionNotFound { - t.Fatalf("Expected cancellation error, got %v", err) - } - } -} - -func TestModePlaybackMissing(t *testing.T) { - // Record initial requests - runID, cassPath, tests := setupTests(t, "record_playback_missing_test") - httpRecorderTest(t, runID, tests, cassPath, recorder.ModeReplayingOrRecording) - - // setup same path but a new runID so requests won't match - runID = time.Now().Format(time.RFC3339Nano) - recorder, server := httpRecorderTestSetup(t, runID, cassPath, recorder.ModeReplaying) - serverURL := server.URL - - defer server.Close() - defer recorder.Stop() - - for _, test := range tests { - resp, err := test.performReq(t, context.Background(), serverURL, recorder) - if resp != nil { - t.Fatalf("Expected response to be nil but was %v", resp) - } - - urlErr, ok := err.(*url.Error) - if !ok { - t.Fatalf("Expected err but was %T %s", err, err) - } - - if urlErr.Err != cassette.ErrInteractionNotFound { - t.Fatalf("Expected cassette.ErrInteractionNotFound but was %T %s", err, err) - } - } -} - -func TestModeDisabled(t *testing.T) { - runID, cassPath, tests := setupTests(t, "record_disabled_test") - - r, _ := httpRecorderTest(t, runID, tests, cassPath, recorder.ModeDisabled) - - if m := r.Mode(); m != recorder.ModeDisabled { - t.Fatalf("Expected disabled mode, got %v", m) - } - - _, err := cassette.Load(cassPath) - // Expect the file to not exist if record is disabled - if !os.IsNotExist(err) { - t.Fatal(err) - } -} - -func TestPassthrough(t *testing.T) { - runID, cassPath, tests := setupTests(t, "test_passthrough") - recorder, server := httpRecorderTestSetup(t, runID, cassPath, recorder.ModeRecording) - serverURL := server.URL - - // Add a passthrough configuration which does not record any requests with - // a specific body. - recorder.AddPassthrough(func(r *http.Request) bool { - if r.Body == nil { - return false - } - var b bytes.Buffer - if _, err := b.ReadFrom(r.Body); err != nil { - return false - } - r.Body = ioutil.NopCloser(&b) - - return b.String() == "alt body" - }) - - t.Log("make http requests") - for _, test := range tests { - test.perform(t, serverURL, recorder) - } - - // Make sure recorder is stopped once done with it - server.Close() - t.Log("server shut down") - - recorder.Stop() - t.Log("recorder stopped") - - // Load the cassette we just stored: - c, err := cassette.Load(cassPath) - if err != nil { - t.Fatal(err) - } - - // Assert that no body exists matching our pass through test - for _, i := range c.Interactions { - body := i.Request.Body - if body == "alt body" { - t.Fatalf("unexpected recording:\t%s", body) - } - } -} - -func TestFilter(t *testing.T) { - dummyBody := "[REDACTED]" - - runID, cassPath, tests := setupTests(t, "test_filter") - recorder, server := httpRecorderTestSetup(t, runID, cassPath, recorder.ModeRecording) - serverURL := server.URL - - // Add a filter which replaces each request body in the stored cassette: - recorder.AddFilter(func(i *cassette.Interaction) error { - i.Request.Body = dummyBody - return nil - }) - - t.Log("make http requests") - for _, test := range tests { - test.perform(t, serverURL, recorder) - } - - // Make sure recorder is stopped once done with it - server.Close() - t.Log("server shut down") - - recorder.Stop() - t.Log("recorder stopped") - - // Load the cassette we just stored: - c, err := cassette.Load(cassPath) - if err != nil { - t.Fatal(err) - } - - // Assert that each body has been set to our dummy value - for i := range tests { - body := c.Interactions[i].Request.Body - if body != dummyBody { - t.Fatalf("got:\t%s\n\twant:\t%s", string(body), string(dummyBody)) - } - } -} - -func TestSaveFilter(t *testing.T) { - dummyBody := "[REDACTED]" - - runID, cassPath, tests := setupTests(t, "test_save_filter") - recorder, server := httpRecorderTestSetup(t, runID, cassPath, recorder.ModeRecording) - serverURL := server.URL - - // Add a filter which replaces each request body in the stored cassette: - recorder.AddSaveFilter(func(i *cassette.Interaction) error { - i.Response.Body = dummyBody - return nil - }) - - t.Log("make http requests") - for _, test := range tests { - test.perform(t, serverURL, recorder) - } - - // Make sure recorder is stopped once done with it - server.Close() - t.Log("server shut down") - - recorder.Stop() - t.Log("recorder stopped") - - // Load the cassette we just stored: - c, err := cassette.Load(cassPath) - if err != nil { - t.Fatal(err) - } - - // Assert that each body has been set to our dummy value - for i := range tests { - body := c.Interactions[i].Response.Body - if body != dummyBody { - t.Fatalf("got:\t%s\n\twant:\t%s", string(body), string(dummyBody)) - } - } -} - -func httpRecorderTestSetup(t *testing.T, runID string, cassPath string, mode recorder.Mode) (*recorder.Recorder, *httptest.Server) { - // Start our recorder - recorder, err := recorder.NewAsMode(cassPath, mode, http.DefaultTransport) - if err != nil { - t.Fatal(err) - } - - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "%s %s", r.Method, runID) - if r.Body != nil { - defer r.Body.Close() - fmt.Fprintln(w) - io.Copy(w, r.Body) - } - })) - - return recorder, server -} - -func httpRecorderTest(t *testing.T, runID string, tests []recordTest, cassPath string, mode recorder.Mode) (*recorder.Recorder, string) { - recorder, server := httpRecorderTestSetup(t, runID, cassPath, mode) - serverURL := server.URL - - t.Log("test http requests") - for _, test := range tests { - test.perform(t, serverURL, recorder) - } - - // Make sure recorder is stopped once done with it - server.Close() - t.Log("server shut down") - - recorder.Stop() - t.Log("recorder stopped") - - return recorder, serverURL -} - -func (test recordTest) perform(t *testing.T, url string, r *recorder.Recorder) { - resp, err := test.performReq(t, context.Background(), url, r) - if err != nil { - t.Fatal(err) - } - defer resp.Body.Close() - - content, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatal(err) - } - if string(content) != test.want { - t.Fatalf("got:\t%s\n\twant:\t%s", string(content), test.want) - } - if resp.ContentLength != int64(test.wantContentLen) { - t.Fatalf("got ContentLength %d want %d", resp.ContentLength, test.wantContentLen) - } -} - -func (test recordTest) performReq(t *testing.T, ctx context.Context, url string, r *recorder.Recorder) (*http.Response, error) { - // Create an HTTP client and inject our transport - client := &http.Client{ - Transport: r, // Inject as transport! - } - - req, err := http.NewRequest(test.method, url, strings.NewReader(test.body)) - if err != nil { - t.Fatal(err) - } - return client.Do(req.WithContext(ctx)) -} - -func setupTests(t *testing.T, name string) (runID, cassPath string, tests []recordTest) { - runID = time.Now().Format(time.RFC3339Nano) - - dir, err := ioutil.TempDir("", "") - if err != nil { - t.Fatal(err) - } - cassPath = path.Join(dir, name) - tests = httpTests(runID) - - return -} diff --git a/vendor/github.com/modocache/gover/.gitignore b/vendor/github.com/modocache/gover/.gitignore deleted file mode 100644 index 5e33ecb..0000000 --- a/vendor/github.com/modocache/gover/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -gover/gover.coverprofile - diff --git a/vendor/github.com/modocache/gover/LICENSE b/vendor/github.com/modocache/gover/LICENSE deleted file mode 100644 index 05485be..0000000 --- a/vendor/github.com/modocache/gover/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2017, Gover Team - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/modocache/gover/README.md b/vendor/github.com/modocache/gover/README.md deleted file mode 100644 index 2a4524a..0000000 --- a/vendor/github.com/modocache/gover/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# gover - -[![Build Status](https://drone.io/github.com/modocache/gover/status.png)](https://drone.io/github.com/modocache/gover/latest) -[![Coverage Status](https://coveralls.io/repos/modocache/gover/badge.png?branch=master)](https://coveralls.io/r/modocache/gover?branch=master) -[![GoDoc](https://godoc.org/github.com/modocache/gover?status.png)](https://godoc.org/github.com/modocache/gover) - -Gather all your *.coverprofile files to send to [coveralls.io](https://coveralls.io/)! - -## Usage - -### Continuous Integration with [coveralls.io](https://coveralls.io/) - -Use with [mattn/goveralls](https://github.com/mattn/goveralls) to send metrics -to [coveralls.io](https://coveralls.io/): - -```sh -go get golang.org/x/tools/cmd/cover -go get github.com/modocache/gover -go get github.com/mattn/goveralls - -go test ./... -gover -goveralls -coverprofile=gover.coverprofile -service drone.io -repotoken $COVERALLS_TOKEN -``` - -### Options - -```console -Usage: gover [root] [out] - -Collects all .coverprofile files rooted in [root] and concatenantes them -into a single file at [out]. - -[root] defaults to the current directory, [out] to 'gover.coverprofile'. -``` diff --git a/vendor/github.com/modocache/gover/gover/gover.go b/vendor/github.com/modocache/gover/gover/gover.go deleted file mode 100644 index b3bb2bf..0000000 --- a/vendor/github.com/modocache/gover/gover/gover.go +++ /dev/null @@ -1,74 +0,0 @@ -/* -Functions for walking a file tree and concatenating all files with the -".coverprofile" extension. Designed for use with the `gover` command-line tool. -*/ -package gover - -import ( - "bytes" - "io/ioutil" - "log" - "os" - "path/filepath" - "regexp" -) - -const ( - /* - The file extension to be concatenated. Currently gover assumes this - will always be '.coverprofile'. - */ - Extension = ".coverprofile" -) - -/* -Walks the file tree at `root`, concatenates all files ending with `Extension`, -then writes those files to `out`. - -`out` is not appended to itself, even if it is under `root` and matches -`Extension`. - -If `root` is an invalid path or does not contain any relevant files, an empty -string is written to `out`. - -If `out` already exists, it is truncated first. If -`out` does not exist, a new file is created with readwrite permissions (0666). -*/ -func Gover(root, out string) { - var buffer bytes.Buffer - abs_out, err := filepath.Abs(out) - if err != nil { - log.Fatal("gover: Could not canonicalize out path:", err) - } - - walkFn := func(path string, info os.FileInfo, err error) error { - if filepath.Ext(path) != Extension { - return err - } - if abs_out == path { - return err - } - - readBytes, readErr := ioutil.ReadFile(path) - if readErr == nil { - readStr := string(readBytes) - - re, _ := regexp.Compile("^mode: [a-z]+\n") - if re.Match(buffer.Bytes()) { - readStr = re.ReplaceAllString(readStr, "") - } - - buffer.WriteString(readStr) - } else { - log.Println("gover: Could not read file:", path) - } - - return err - } - - filepath.Walk(root, walkFn) - err = ioutil.WriteFile(out, buffer.Bytes(), 0666) - if err != nil { - log.Fatal("gover: Could not write to out:", out) - } -} diff --git a/vendor/github.com/modocache/gover/main.go b/vendor/github.com/modocache/gover/main.go deleted file mode 100644 index 35dd0fc..0000000 --- a/vendor/github.com/modocache/gover/main.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Usage: gover [root] [out] - -Collects all .coverprofile files rooted in [root] and concatenantes them -into a single file at [out]. - -[out] is not concatenated onto itself, even if it is in [root] and has a -.coverprofile extension. - -[root] defaults to the current directory, [out] to 'gover.coverprofile'. - -For more details, consult the README: https://github.com/modocache/gover -*/ -package main - -import ( - "flag" - "fmt" - "github.com/modocache/gover/gover" - "log" - "os" -) - -const ( - defaultOut = "gover.coverprofile" - usage = "Usage: gover [root] [out]\n\nCollects all .coverprofile files rooted in [root] and concatenantes them into a single file at [out].\n[root] defaults to the current directory, [out] to 'gover.coverprofile'.\n\nFor more details see: https://github.com/modocache/gover" -) - -func defaultRoot() string { - root, err := os.Getwd() - if err != nil { - log.Fatal("gover: Could not get current working directory") - } - return root -} - -func parseArgs(args []string) (string, string) { - var root, out string - if len(args) == 0 { - root, out = defaultRoot(), defaultOut - } else if len(args) == 1 { - root, out = args[0], defaultOut - } else { - root, out = args[0], args[1] - } - - return root, out -} - -func main() { - flag.Parse() - args := flag.Args() - if len(args) > 2 { - fmt.Println(usage) - os.Exit(1) - } - - root, out := parseArgs(args) - gover.Gover(root, out) -} diff --git a/vendor/github.com/modocache/gover/main_test.sh b/vendor/github.com/modocache/gover/main_test.sh deleted file mode 100644 index ef34e24..0000000 --- a/vendor/github.com/modocache/gover/main_test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -PREFIX="test_main.sh:" -GOVER="$GOPATH/bin/gover" - -echo "$PREFIX $GOVER" -$GOVER || exit 1 -echo "$PREFIX rm gover.coverprofile" -rm gover.coverprofile || exit 1 - -echo "$PREFIX $GOVER gover/_fixtures/nested_cover_profiles" -$GOVER gover/_fixtures/nested_cover_profiles || exit 1 -echo "$PREFIX rm gover.coverprofile" -rm gover.coverprofile || exit 1 - -echo "$PREFIX $GOVER gover/_fixtures/nested_cover_profiles out.coverprofile" -$GOVER gover/_fixtures/nested_cover_profiles out.coverprofile || exit 1 -echo "$PREFIX rm out.coverprofile" -rm out.coverprofile || exit 1 diff --git a/vendor/gopkg.in/yaml.v3/go.mod b/vendor/gopkg.in/yaml.v3/go.mod deleted file mode 100644 index f407ea3..0000000 --- a/vendor/gopkg.in/yaml.v3/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module "gopkg.in/yaml.v3" - -require ( - "gopkg.in/check.v1" v0.0.0-20161208181325-20d25e280405 -) diff --git a/vendor/modules.txt b/vendor/modules.txt index 09cda9b..6d82c2a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,11 +1,3 @@ -# github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 -## explicit -github.com/modocache/gover -github.com/modocache/gover/gover -# github.com/onsi/ginkgo v1.16.4 -## explicit -# github.com/onsi/gomega v1.13.0 -## explicit # gopkg.in/yaml.v3 v3.0.1 ## explicit gopkg.in/yaml.v3