Skip to content

Commit

Permalink
Add tests (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
IljaN authored and labkode committed Sep 23, 2019
1 parent 3a88230 commit db6cf7d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
- Giuseppe <giuseppe.lopresti@cern.ch>
- Giuseppe Lo Presti <giuseppe.lopresti@cern.ch>
- Hugo Gonzalez Labrador <github@hugo.labkode.com>
- Ilja Neumann <ineumann@owncloud.com>
- Jörn Friedrich Dreyer <jfd@butonic.de>
- Mohitty <mohitt@iitk.ac.in>
51 changes: 51 additions & 0 deletions pkg/crypto/crypto_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2018-2019 CERN
//
// 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.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package crypto

import (
"io"
"strings"
"testing"
)

func TestChecksums(t *testing.T) {
tests := map[string]struct {
xsFunc func(r io.Reader) (string, error)
input string
expectedXS string
}{
"adler32_hello": {ComputeAdler32XS, "Hello World!", "1c49043e"},
"sha1_hello": {ComputeSHA1XS, "Hello World!", "2ef7bde608ce5404e97d5f042f95f89f1c232871"},
"md5_hello": {ComputeMD5XS, "Hello World!", "ed076287532e86365e841e92bfc50d8c"},
}

for name := range tests {
var tc = tests[name]
t.Run(name, func(t *testing.T) {
actual, err := tc.xsFunc(strings.NewReader(tc.input))
if err != nil {
t.Fatalf("%v returned an unexpected error: %v", t.Name(), err)
}

if actual != tc.expectedXS {
t.Fatalf("%v returned wrong checksum:\n\tAct: %v\n\tExp: %v", t.Name(), actual, tc.expectedXS)
}
})
}
}

0 comments on commit db6cf7d

Please sign in to comment.