Skip to content

Commit

Permalink
[TEST] close webserver and catch valid panic
Browse files Browse the repository at this point in the history
  • Loading branch information
genofire committed Oct 7, 2017
1 parent 8d2e8d2 commit 557a440
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion webserver/webserver_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package webserver

import (
"fmt"
"testing"
"time"

Expand All @@ -13,10 +14,23 @@ func TestWebserver(t *testing.T) {
srv := New(":8080", "/tmp")
assert.NotNil(srv)

go Start(srv)
go func() {
defer func() {
if r := recover(); r != nil {
fmt.Println("catch valid panic")
assert.Equal("http: Server closed", r)
}
}()

Start(srv)

}()

time.Sleep(time.Millisecond * 200)

assert.Panics(func() {
Start(srv)
}, "not allowed to listen twice")

srv.Close()
}

0 comments on commit 557a440

Please sign in to comment.