github.com/minio/mc@v0.0.0-20240507152021-646712d5e5fb/pkg/probe/probe_test.go (about) 1 // Copyright (c) 2015-2021 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 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 Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package probe_test 19 20 import ( 21 "os" 22 "testing" 23 24 "github.com/minio/mc/pkg/probe" 25 check "gopkg.in/check.v1" 26 ) 27 28 func Test(t *testing.T) { check.TestingT(t) } 29 30 type MySuite struct{} 31 32 var _ = check.Suite(&MySuite{}) 33 34 func testDummy0() *probe.Error { 35 _, e := os.Stat("this-file-cannot-exit") 36 return probe.NewError(e) 37 } 38 39 func testDummy1() *probe.Error { 40 return testDummy0().Trace("DummyTag1") 41 } 42 43 func testDummy2() *probe.Error { 44 return testDummy1().Trace("DummyTag2") 45 } 46 47 func (s *MySuite) TestProbe(c *check.C) { 48 probe.Init() // Set project's root source path. 49 probe.SetAppInfo("Commit-ID", "7390cc957239") 50 es := testDummy2().Trace("TopOfStack") 51 // Uncomment the following Println to visually test probe call trace. 52 // fmt.Println("Expecting a simulated error here.", es) 53 c.Assert(es, check.Not(check.Equals), nil) 54 55 newES := es.Trace() 56 c.Assert(newES, check.Not(check.Equals), nil) 57 } 58 59 func (s *MySuite) TestWrappedError(c *check.C) { 60 _, e := os.Stat("this-file-cannot-exit") 61 es := probe.NewError(e) // *probe.Error 62 e = probe.WrapError(es) // *probe.WrappedError 63 _, ok := probe.UnwrapError(e) 64 c.Assert(ok, check.Equals, true) 65 }