Skip to content

Commit

Permalink
👷 Add testcases for ListenTLS (#1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyonlin authored May 7, 2021
1 parent 0ce98d7 commit 22848f7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,35 @@ func Test_App_Listen_Prefork(t *testing.T) {
utils.AssertEqual(t, nil, app.Listen(":99999"))
}

// go test -run Test_App_ListenTLS
func Test_App_ListenTLS(t *testing.T) {
app := New()

// invalid port
utils.AssertEqual(t, false, app.ListenTLS(":99999", "./.github/testdata/ssl.pem", "./.github/testdata/ssl.key") == nil)
// missing perm/cert file
utils.AssertEqual(t, false, app.ListenTLS(":0", "", "./.github/testdata/ssl.key") == nil)

go func() {
time.Sleep(1000 * time.Millisecond)
utils.AssertEqual(t, nil, app.Shutdown())
}()

utils.AssertEqual(t, nil, app.ListenTLS(":0", "./.github/testdata/ssl.pem", "./.github/testdata/ssl.key"))
}

// go test -run Test_App_ListenTLS_Prefork
func Test_App_ListenTLS_Prefork(t *testing.T) {
testPreforkMaster = true

app := New(Config{DisableStartupMessage: true, Prefork: true})

// invalid key file content
utils.AssertEqual(t, false, app.ListenTLS(":0", "./.github/testdata/ssl.pem", "./.github/testdata/template.html") == nil)

utils.AssertEqual(t, nil, app.ListenTLS(":99999", "./.github/testdata/ssl.pem", "./.github/testdata/ssl.key"))
}

// go test -run Test_App_Listener
func Test_App_Listener(t *testing.T) {
app := New()
Expand All @@ -990,7 +1019,7 @@ func Test_App_Listener_Prefork(t *testing.T) {
utils.AssertEqual(t, nil, app.Listener(ln))
}

func Test_App_Listener_TLS(t *testing.T) {
func Test_App_Listener_TLS_Listener(t *testing.T) {
// Create tls certificate
cer, err := tls.LoadX509KeyPair("./.github/testdata/ssl.pem", "./.github/testdata/ssl.key")
if err != nil {
Expand Down

0 comments on commit 22848f7

Please sign in to comment.