github.com/cs3org/reva/v2@v2.27.7/pkg/crypto/crypto_test.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package crypto 20 21 import ( 22 "io" 23 "strings" 24 "testing" 25 ) 26 27 func TestChecksums(t *testing.T) { 28 tests := map[string]struct { 29 xsFunc func(r io.Reader) (string, error) 30 input string 31 expectedXS string 32 }{ 33 "adler32_hello": {ComputeAdler32XS, "Hello World!", "1c49043e"}, 34 "sha1_hello": {ComputeSHA1XS, "Hello World!", "2ef7bde608ce5404e97d5f042f95f89f1c232871"}, 35 "md5_hello": {ComputeMD5XS, "Hello World!", "ed076287532e86365e841e92bfc50d8c"}, 36 } 37 38 for name := range tests { 39 var tc = tests[name] 40 t.Run(name, func(t *testing.T) { 41 actual, err := tc.xsFunc(strings.NewReader(tc.input)) 42 if err != nil { 43 t.Fatalf("%v returned an unexpected error: %v", t.Name(), err) 44 } 45 46 if actual != tc.expectedXS { 47 t.Fatalf("%v returned wrong checksum:\n\tAct: %v\n\tExp: %v", t.Name(), actual, tc.expectedXS) 48 } 49 }) 50 } 51 }