Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NewTube function #45

Merged
merged 1 commit into from May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
func NewConn(conn io.ReadWriteCloser) *Conn {
c := new(Conn)
c.c = textproto.NewConn(conn)
c.Tube = Tube{c, "default"}
c.Tube = *NewTube(c, "default")
c.TubeSet = *NewTubeSet(c, "default")
c.used = "default"
c.watched = map[string]bool{"default": true}
Expand Down
8 changes: 4 additions & 4 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func TestNameTooLong(t *testing.T) {
c := NewConn(mock("", ""))

tube := Tube{c, string(make([]byte, 201))}
tube := NewTube(c, string(make([]byte, 201)))
_, err := tube.Put([]byte("foo"), 0, 0, 0)
if e, ok := err.(NameError); !ok || e.Err != ErrTooLong {
t.Fatal(err)
Expand All @@ -21,7 +21,7 @@ func TestNameTooLong(t *testing.T) {
func TestNameEmpty(t *testing.T) {
c := NewConn(mock("", ""))

tube := Tube{c, ""}
tube := NewTube(c, "")
_, err := tube.Put([]byte("foo"), 0, 0, 0)
if e, ok := err.(NameError); !ok || e.Err != ErrEmpty {
t.Fatal(err)
Expand All @@ -34,7 +34,7 @@ func TestNameEmpty(t *testing.T) {
func TestNameBadChar(t *testing.T) {
c := NewConn(mock("", ""))

tube := Tube{c, "*"}
tube := NewTube(c, "*")
_, err := tube.Put([]byte("foo"), 0, 0, 0)
if e, ok := err.(NameError); !ok || e.Err != ErrBadChar {
t.Fatal(err)
Expand All @@ -61,7 +61,7 @@ func TestUse(t *testing.T) {
"use foo\r\nput 0 0 0 5\r\nhello\r\n",
"USING foo\r\nINSERTED 1\r\n",
))
tube := Tube{c, "foo"}
tube := NewTube(c, "foo")
id, err := tube.Put([]byte("hello"), 0, 0, 0)
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Example_put() {
}

func Example_putOtherTube() {
tube := &beanstalk.Tube{Conn: conn, Name: "mytube"}
tube := beanstalk.NewTube(conn, "mytube")
id, err := tube.Put([]byte("myjob"), 1, 0, time.Minute)
if err != nil {
panic(err)
Expand Down
5 changes: 5 additions & 0 deletions tube.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ type Tube struct {
Name string
}

// NewTube returns a new Tube representing the given name.
func NewTube(c *Conn, name string) *Tube {
return &Tube{c, name}
}

// Put puts a job into tube t with priority pri and TTR ttr, and returns
// the id of the newly-created job. If delay is nonzero, the server will
// wait the given amount of time after returning to the client and before
Expand Down