github.com/Lephar/snapd@v0.0.0-20210825215435-c7fba9cef4d2/progress/progress_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2014-2015 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package progress_test 21 22 import ( 23 "bytes" 24 "fmt" 25 "testing" 26 27 . "gopkg.in/check.v1" 28 29 "github.com/snapcore/snapd/progress" 30 "github.com/snapcore/snapd/progress/progresstest" 31 ) 32 33 // Hook up check.v1 into the "go test" runner 34 func Test(t *testing.T) { TestingT(t) } 35 36 type ProgressTestSuite struct { 37 } 38 39 var _ = Suite(&ProgressTestSuite{}) 40 41 func (ts *ProgressTestSuite) testNotify(c *C, t progress.Meter, desc, expected string) { 42 var buf bytes.Buffer 43 defer progress.MockStdout(&buf)() 44 45 comment := Commentf(desc) 46 47 t.Notify("blah blah") 48 49 c.Check(buf.String(), Equals, expected, comment) 50 } 51 52 func (ts *ProgressTestSuite) TestQuietNotify(c *C) { 53 ts.testNotify(c, &progress.QuietMeter{}, "quiet", "blah blah\n") 54 } 55 56 func (ts *ProgressTestSuite) TestANSINotify(c *C) { 57 expected := fmt.Sprint("\r", progress.ExitAttributeMode, progress.ClrEOL, "blah blah\n") 58 ts.testNotify(c, &progress.ANSIMeter{}, "ansi", expected) 59 } 60 61 func (ts *ProgressTestSuite) TestTestingNotify(c *C) { 62 p := &progresstest.Meter{} 63 ts.testNotify(c, p, "test", "") 64 c.Check(p.Notices, DeepEquals, []string{"blah blah"}) 65 }