OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package internal |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 |
| 10 "infra/tools/cipd/internal/messages" |
| 11 |
| 12 . "github.com/smartystreets/goconvey/convey" |
| 13 ) |
| 14 |
| 15 func TestChecksumCheckingWorks(t *testing.T) { |
| 16 msg := messages.TagCache{ |
| 17 Entries: []*messages.TagCache_Entry{ |
| 18 &messages.TagCache_Entry{ |
| 19 Package: strPtr("package"), |
| 20 Tag: strPtr("tag"), |
| 21 InstanceId: strPtr("instance_id"), |
| 22 }, |
| 23 }, |
| 24 } |
| 25 |
| 26 Convey("Works", t, func(c C) { |
| 27 buf, err := MarshalWithSHA1(&msg) |
| 28 So(err, ShouldBeNil) |
| 29 out := messages.TagCache{} |
| 30 So(UnmarshalWithSHA1(buf, &out), ShouldBeNil) |
| 31 So(out, ShouldResemble, msg) |
| 32 }) |
| 33 |
| 34 Convey("Rejects bad msg", t, func(c C) { |
| 35 buf, err := MarshalWithSHA1(&msg) |
| 36 So(err, ShouldBeNil) |
| 37 buf[10] = 0 |
| 38 out := messages.TagCache{} |
| 39 So(UnmarshalWithSHA1(buf, &out), ShouldNotBeNil) |
| 40 }) |
| 41 } |
| 42 |
| 43 func strPtr(s string) *string { |
| 44 return &s |
| 45 } |
OLD | NEW |