Skip to content

Commit

Permalink
Remove trueVerifier from main logic (kubernetes-sigs#362)
Browse files Browse the repository at this point in the history
* Remove trueVerifier from main logic

This verifier implementation is only used in tests, so it should be defined there.

* Remove test for trueVerifier
  • Loading branch information
corneliusweig authored and k8s-ci-robot committed Oct 31, 2019
1 parent d67e087 commit 613ee9b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 46 deletions.
14 changes: 11 additions & 3 deletions pkg/download/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestDownloader_Get(t *testing.T) {
{
name: "successful get",
fields: fields{
verifier: NewInsecureVerifier(),
verifier: newTrueVerifier(),
fetcher: NewFileFetcher(filepath.Join(testdataPath(), "test-with-directory.zip")),
},
uri: "foo/bar/test-with-directory.zip",
Expand All @@ -174,7 +174,7 @@ func TestDownloader_Get(t *testing.T) {
{
name: "fail get by fetching",
fields: fields{
verifier: NewInsecureVerifier(),
verifier: newTrueVerifier(),
fetcher: errorFetcher{},
},
uri: "foo/bar/test-with-directory.zip",
Expand Down Expand Up @@ -217,7 +217,7 @@ func Test_download(t *testing.T) {
name: "successful fetch",
args: args{
url: filePath,
verifier: NewInsecureVerifier(),
verifier: newTrueVerifier(),
fetcher: NewFileFetcher(filePath),
},
wantReader: bytes.NewReader(downloadOriginal),
Expand Down Expand Up @@ -267,6 +267,14 @@ func Test_download(t *testing.T) {
}
}

var _ Verifier = trueVerifier{}

type trueVerifier struct{ io.Writer }

// newTrueVerifier returns a Verifier that always verifies to true.
func newTrueVerifier() Verifier { return trueVerifier{ioutil.Discard} }
func (trueVerifier) Verify() error { return nil }

var _ Verifier = falseVerifier{}

type falseVerifier struct{ io.Writer }
Expand Down
9 changes: 0 additions & 9 deletions pkg/download/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/hex"
"hash"
"io"
"io/ioutil"

"github.com/golang/glog"
"github.com/pkg/errors"
Expand Down Expand Up @@ -55,11 +54,3 @@ func (v sha256Verifier) Verify() error {
}
return errors.Errorf("checksum does not match, want: %x, got %x", v.wantedHash, v.Sum(nil))
}

var _ Verifier = trueVerifier{}

type trueVerifier struct{ io.Writer }

// NewInsecureVerifier returns a Verifier that always verifies to true.
func NewInsecureVerifier() Verifier { return trueVerifier{ioutil.Discard} }
func (trueVerifier) Verify() error { return nil }
34 changes: 0 additions & 34 deletions pkg/download/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,3 @@ func TestSha256Verifier(t *testing.T) {
})
}
}

func TestTrueVerifier(t *testing.T) {
tests := []struct {
name string
write []byte
wantError bool
}{
{
name: "test okay hash",
write: []byte("hello world"),
wantError: false,
},
{
name: "test wrong hash",
write: []byte("HELLO WORLD"),
wantError: false,
},
{
name: "test empty hash",
write: []byte{},
wantError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := NewInsecureVerifier()
_, _ = io.Copy(v, bytes.NewReader(tt.write))
if err := v.Verify(); (err != nil) != tt.wantError {
t.Errorf("NewInsecureVerifier().Write(%x).Verify() = %v, wantReader %v", tt.write, err, tt.wantError)
return
}
})
}
}

0 comments on commit 613ee9b

Please sign in to comment.