github.com/gfleury/gobbs@v0.0.0-20200831213239-44ca2b94c1a1/pullrequests/delete_test.go (about) 1 package pullrequests 2 3 import ( 4 "io/ioutil" 5 "os" 6 7 "github.com/gfleury/gobbs/common" 8 9 "gopkg.in/check.v1" 10 ) 11 12 func (s *S) TestDeleteInvalidHost(c *check.C) { 13 *s.host = "http://localhost:7992" 14 15 os.Args = []string{"pr", "create", "featureBranch", "master"} 16 17 ctx := common.APIClientContext(&s.stashInfo) 18 err := Delete.ExecuteContext(ctx) 19 c.Assert(err, check.ErrorMatches, ".*connect: connection refused") 20 } 21 22 func (s *S) TestDeleteInvalidHostTimeouted(c *check.C) { 23 *s.host = "http://localhost:7992" 24 25 os.Args = []string{"pr", "create", "featureBranch", "master"} 26 27 *s.stashInfo.Timeout() = 0 28 29 ctx := common.APIClientContext(&s.stashInfo) 30 err := Delete.ExecuteContext(ctx) 31 c.Assert(err, check.ErrorMatches, ".*context deadline exceeded") 32 *s.stashInfo.Timeout() = 2 33 } 34 35 func (s *S) TestDeleteValidHost(c *check.C) { 36 *s.host = "http://localhost:7993" 37 38 os.Args = []string{"pr", "create", "featureBranch", "master"} 39 40 s.mockStdout() 41 42 ctx := common.APIClientContext(&s.stashInfo) 43 err := Delete.ExecuteContext(ctx) 44 c.Assert(err, check.IsNil) 45 46 s.closeMockStdout() 47 48 got, err := ioutil.ReadAll(s.readStdout) 49 c.Assert(err, check.IsNil) 50 51 want, err := ioutil.ReadFile("mocked_responses/pullrequests_delete.output") 52 c.Assert(err, check.IsNil) 53 54 c.Assert(string(got), check.Equals, string(want)) 55 }