import ( "testing" "github.com/peterh/liner" . "gopkg.in/check.v1" ) func TestLiner(t *testing.T) { TestingT(t) } type LinerSuite struct{} var _ = Suite(&LinerSuite{}) func (s *LinerSuite) TestLinerPrompt(c *C) { line := liner.NewLiner() defer line.Close() line.SetCtrlCAborts(true) prompt := "> " result, err := line.Prompt(prompt) c.Assert(err, Equals, nil) c.Assert(result, Equals, "") }
import ( "net/http" "net/http/httptest" "io/ioutil" . "gopkg.in/check.v1" ) func TestHandler(t *testing.T) { TestingT(t) } type HandlerSuite struct{} var _ = Suite(&HandlerSuite{}) func (s *HandlerSuite) TestHandler(c *C) { req, err := http.NewRequest("GET", "/", nil) c.Assert(err, Equals, nil) w := httptest.NewRecorder() handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte("OK")) }) handler.ServeHTTP(w, req) resp := w.Result() body, err := ioutil.ReadAll(resp.Body) c.Assert(err, Equals, nil) c.Assert(resp.StatusCode, Equals, http.StatusOK) c.Assert(string(body), Equals, "OK") }This example shows how to write a functional test using the check library. In this case, the test is for an HTTP handler that responds with a "OK" message when a GET request is made to the root URL ("/"). The test creates a new HTTP request and handler, makes the request, and then verifies that the response code is 200 and the body of the response is "OK". Overall, the go github.com.pgpst.pgpst.internal.gopkg.in.check.v1 package library is a powerful tool for testing in Go. It provides a simple and effective way to write tests that can ensure your code works as intended.