Skip to content

Commit

Permalink
test: add timeout test
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Aug 24, 2022
1 parent 9519145 commit 011c9bb
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions cmd/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cmd
import (
"log"
"testing"
"time"

"github.com/charmbracelet/charm/client"
"github.com/charmbracelet/charm/proto"
"github.com/charmbracelet/charm/server"
"github.com/charmbracelet/charm/testserver"
)

Expand Down Expand Up @@ -68,12 +70,32 @@ func TestInvalidLinkGen(t *testing.T) {
})
}

// TestTimeoutLink
func TestTimeoutLink(t *testing.T) {
client1 := testserver.SetupTestServer(t, func(c *server.Config) *server.Config {
return c.WithLinkTimeout(5 * time.Second)
})
lc := make(chan string, 1)
t.Run("link client 1", func(t *testing.T) {
t.Parallel()
lh := &linkHandlerTest{desc: "client1", linkChan: lc, approve: true}
// pass testing.t to it, assert error
err := client1.LinkGen(lh)
if err != nil {
t.Fatalf("failed to link client 1: %v", err)
}
if lh.status != timedout {
t.Fatalf("expected link to timeout, got: %v", lh.status)
}
})
}

// use these status codes for assertions in tests
type statusCode uint

const (
timedout statusCode = iota
ok
ok statusCode = iota
timedout
invalidToken
requestDenied
)
Expand Down

0 comments on commit 011c9bb

Please sign in to comment.