Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit 5c18378

Browse files
committed
trying to fix govcr.
1 parent 90deda7 commit 5c18378

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

pkg/scm/scm_bitbucket_test.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package scm_test
22

33
import (
4+
"crypto/tls"
45
"github.com/analogj/capsulecd/pkg/config/mock"
56
"github.com/analogj/capsulecd/pkg/pipeline"
67
"github.com/analogj/capsulecd/pkg/scm"
78
"github.com/analogj/capsulecd/pkg/utils"
8-
"crypto/tls"
99
"github.com/golang/mock/gomock"
1010
"github.com/seborama/govcr"
1111
"github.com/stretchr/testify/require"
@@ -14,7 +14,6 @@ import (
1414
"net/http"
1515
"os"
1616
"path"
17-
"strings"
1817
"testing"
1918
)
2019

@@ -34,22 +33,17 @@ func bitbucketVcrSetup(t *testing.T) *http.Client {
3433
Logging: true,
3534
CassettePath: path.Join("testdata", "govcr-fixtures"),
3635
Client: &insecureClient,
37-
ExcludeHeaderFunc: func(key string) bool {
38-
// HTTP headers are case-insensitive
39-
//return strings.ToLower(key) == "user-agent" || strings.ToLower(key) == "accept"
40-
return strings.ToLower(key) == "user-agent" || strings.ToLower(key) == "authorization"
41-
},
42-
RequestFilterFunc: func(reqHeader http.Header, reqBody []byte) (*http.Header, *[]byte) {
43-
reqHeader.Set("Authorization", "Basic UExBQ0VIT0xERVI6UExBQ0VIT0xERVI=") //placeholder:placeholder
44-
45-
return &reqHeader, &reqBody
46-
},
4736

4837
//this line ensures that we do not attempt to create new recordings.
4938
//Comment this out if you would like to make recordings.
5039
DisableRecording: DISABLE_RECORDINGS,
5140
}
5241

42+
// HTTP headers are case-insensitive
43+
vcrConfig.RequestFilters.Add(govcr.RequestDeleteHeaderKeys("User-Agent", "user-agent"))
44+
vcrConfig.RequestFilters.Add(govcr.RequestDeleteHeaderKeys("Authorization", "authorization"))
45+
vcrConfig.RequestFilters.Add(govcr.RequestAddHeaderValue("Authorization", "Basic UExBQ0VIT0xERVI6UExBQ0VIT0xERVI=")) //placeholder:placeholder
46+
5347
vcr := govcr.NewVCR(t.Name(), &vcrConfig)
5448
return vcr.Client
5549
}

pkg/scm/scm_github_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ import (
55
"github.com/stretchr/testify/require"
66
"testing"
77

8-
"github.com/analogj/capsulecd/pkg/config/mock"
9-
"github.com/analogj/capsulecd/pkg/pipeline"
108
"context"
119
"crypto/tls"
10+
"github.com/analogj/capsulecd/pkg/config/mock"
11+
"github.com/analogj/capsulecd/pkg/pipeline"
1212
"github.com/golang/mock/gomock"
1313
"github.com/seborama/govcr"
1414
"golang.org/x/oauth2"
1515
"io/ioutil"
1616
"net/http"
1717
"os"
1818
"path"
19-
"strings"
2019
)
2120

2221
func githubVcrSetup(t *testing.T) *http.Client {
@@ -46,17 +45,16 @@ func githubVcrSetup(t *testing.T) *http.Client {
4645
Logging: true,
4746
CassettePath: path.Join("testdata", "govcr-fixtures"),
4847
Client: tc,
49-
ExcludeHeaderFunc: func(key string) bool {
50-
// HTTP headers are case-insensitive
51-
//return strings.ToLower(key) == "user-agent" || strings.ToLower(key) == "accept"
52-
return strings.ToLower(key) == "user-agent"
53-
},
5448

5549
//this line ensures that we do not attempt to create new recordings.
5650
//Comment this out if you would like to make recordings.
5751
DisableRecording: true,
5852
}
5953

54+
// HTTP headers are case-insensitive
55+
vcrConfig.RequestFilters.Add(govcr.RequestDeleteHeaderKeys("User-Agent", "user-agent"))
56+
57+
6058
vcr := govcr.NewVCR(t.Name(), &vcrConfig)
6159
return vcr.Client
6260
}

0 commit comments

Comments
 (0)