From db6cf7db66702733ec42a335c3dc216570169876 Mon Sep 17 00:00:00 2001 From: Ilja Neumann Date: Mon, 23 Sep 2019 17:04:48 +0200 Subject: [PATCH] Add tests (#267) --- CONTRIBUTORS.md | 1 + pkg/crypto/crypto_test.go | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 pkg/crypto/crypto_test.go diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f672d40e82..018e0cabb4 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -4,5 +4,6 @@ - Giuseppe - Giuseppe Lo Presti - Hugo Gonzalez Labrador +- Ilja Neumann - Jörn Friedrich Dreyer - Mohitty diff --git a/pkg/crypto/crypto_test.go b/pkg/crypto/crypto_test.go new file mode 100644 index 0000000000..37f15aeddf --- /dev/null +++ b/pkg/crypto/crypto_test.go @@ -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) + } + }) + } +}