go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cipd/common/hash_test.go (about) 1 // Copyright 2017 The LUCI Authors. 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 package common 16 17 import ( 18 "testing" 19 20 api "go.chromium.org/luci/cipd/api/cipd/v1" 21 22 . "github.com/smartystreets/goconvey/convey" 23 . "go.chromium.org/luci/common/testing/assertions" 24 ) 25 26 func TestNewHash(t *testing.T) { 27 t.Parallel() 28 29 Convey("Unspecified", t, func() { 30 _, err := NewHash(api.HashAlgo_HASH_ALGO_UNSPECIFIED) 31 So(err, ShouldErrLike, "not specified") 32 }) 33 34 Convey("Unknown", t, func() { 35 _, err := NewHash(12345) 36 So(err, ShouldErrLike, "unsupported") 37 }) 38 39 Convey("SHA1", t, func() { 40 algo, err := NewHash(api.HashAlgo_SHA1) 41 So(err, ShouldBeNil) 42 So(algo, ShouldNotBeNil) 43 So(ObjectRefFromHash(algo), ShouldResembleProto, &api.ObjectRef{ 44 HashAlgo: api.HashAlgo_SHA1, 45 HexDigest: "da39a3ee5e6b4b0d3255bfef95601890afd80709", 46 }) 47 }) 48 49 Convey("SHA256", t, func() { 50 algo, err := NewHash(api.HashAlgo_SHA256) 51 So(err, ShouldBeNil) 52 So(algo, ShouldNotBeNil) 53 So(ObjectRefFromHash(algo), ShouldResembleProto, &api.ObjectRef{ 54 HashAlgo: api.HashAlgo_SHA256, 55 HexDigest: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 56 }) 57 }) 58 }