github.com/drone/runner-go@v1.12.0/manifest/signature_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package manifest 6 7 import ( 8 "testing" 9 10 "github.com/buildkite/yaml" 11 "github.com/google/go-cmp/cmp" 12 ) 13 14 var mockSignatureYaml = []byte(` 15 --- 16 kind: signature 17 hmac: N2NmYjA3ODQwNTY1ODFlY2E5MGJmOWI1NDk0NDFhMTEK 18 `) 19 20 var mockSignature = &Signature{ 21 Kind: "signature", 22 Hmac: "N2NmYjA3ODQwNTY1ODFlY2E5MGJmOWI1NDk0NDFhMTEK", 23 } 24 25 func TestSignatureUnmarshal(t *testing.T) { 26 a := new(Signature) 27 b := mockSignature 28 yaml.Unmarshal(mockSignatureYaml, a) 29 if diff := cmp.Diff(a, b); diff != "" { 30 t.Error("Failed to parse signature") 31 t.Log(diff) 32 } 33 } 34 35 func TestSignatureValidate(t *testing.T) { 36 sig := Signature{Hmac: "1234"} 37 if err := sig.Validate(); err != nil { 38 t.Error(err) 39 return 40 } 41 42 sig.Hmac = "" 43 if err := sig.Validate(); err == nil { 44 t.Errorf("Expect invalid signature error") 45 } 46 }