Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
7751f4fb
Commit
7751f4fb
authored
Jun 05, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API integration tests with http/1.1 and SPDY
parent
3cd0b876
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
228 additions
and
0 deletions
+228
-0
integration-tests/nghttpx_http1_test.go
integration-tests/nghttpx_http1_test.go
+112
-0
integration-tests/nghttpx_spdy_test.go
integration-tests/nghttpx_spdy_test.go
+112
-0
integration-tests/server_tester.go
integration-tests/server_tester.go
+4
-0
No files found.
integration-tests/nghttpx_http1_test.go
View file @
7751f4fb
...
...
@@ -3,6 +3,7 @@ package nghttp2
import
(
"bufio"
"bytes"
"encoding/json"
"fmt"
"golang.org/x/net/http2/hpack"
"golang.org/x/net/websocket"
...
...
@@ -793,3 +794,114 @@ func TestH1H2RespPhaseReturn(t *testing.T) {
t
.
Errorf
(
"body = %v; want %v"
,
got
,
want
)
}
}
// TestH1APIBackendReplace exercise backend/replace API endpoint
// routine for successful case.
func
TestH1APIBackendReplace
(
t
*
testing
.
T
)
{
st
:=
newServerTesterConnectPort
([]
string
{
"-f127.0.0.1,3010;api;no-tls"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
t
.
Fatalf
(
"request should not be forwarded"
)
},
3010
)
defer
st
.
Close
()
res
,
err
:=
st
.
http1
(
requestParam
{
name
:
"TestH1APIBackendReplace"
,
path
:
"/api/v1beta1/backend/replace"
,
method
:
"PUT"
,
body
:
[]
byte
(
`# comment
backend=127.0.0.1,3011
`
),
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http1() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"res.status: %v; want %v"
,
got
,
want
)
}
var
apiResp
APIResponse
err
=
json
.
Unmarshal
(
res
.
body
,
&
apiResp
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error unmarshaling API response: %v"
,
err
)
}
if
got
,
want
:=
apiResp
.
Status
,
"Success"
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
if
got
,
want
:=
apiResp
.
Code
,
200
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
}
// TestH1APIBackendReplaceBadMethod exercise backend/replace API
// endpoint routine with bad method.
func
TestH1APIBackendReplaceBadMethod
(
t
*
testing
.
T
)
{
st
:=
newServerTesterConnectPort
([]
string
{
"-f127.0.0.1,3010;api;no-tls"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
t
.
Fatalf
(
"request should not be forwarded"
)
},
3010
)
defer
st
.
Close
()
res
,
err
:=
st
.
http1
(
requestParam
{
name
:
"TestH1APIBackendReplaceBadMethod"
,
path
:
"/api/v1beta1/backend/replace"
,
method
:
"GET"
,
body
:
[]
byte
(
`# comment
backend=127.0.0.1,3011
`
),
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http1() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
405
;
got
!=
want
{
t
.
Errorf
(
"res.status: %v; want %v"
,
got
,
want
)
}
var
apiResp
APIResponse
err
=
json
.
Unmarshal
(
res
.
body
,
&
apiResp
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error unmarshaling API response: %v"
,
err
)
}
if
got
,
want
:=
apiResp
.
Status
,
"Failure"
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
if
got
,
want
:=
apiResp
.
Code
,
405
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
}
// TestH1APINotFound exercise backend/replace API endpoint routine
// when API endpoint is not found.
func
TestH1APINotFound
(
t
*
testing
.
T
)
{
st
:=
newServerTesterConnectPort
([]
string
{
"-f127.0.0.1,3010;api;no-tls"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
t
.
Fatalf
(
"request should not be forwarded"
)
},
3010
)
defer
st
.
Close
()
res
,
err
:=
st
.
http1
(
requestParam
{
name
:
"TestH1APINotFound"
,
path
:
"/api/notfound"
,
method
:
"GET"
,
body
:
[]
byte
(
`# comment
backend=127.0.0.1,3011
`
),
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http1() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
404
;
got
!=
want
{
t
.
Errorf
(
"res.status: %v; want %v"
,
got
,
want
)
}
var
apiResp
APIResponse
err
=
json
.
Unmarshal
(
res
.
body
,
&
apiResp
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error unmarshaling API response: %v"
,
err
)
}
if
got
,
want
:=
apiResp
.
Status
,
"Failure"
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
if
got
,
want
:=
apiResp
.
Code
,
404
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
}
integration-tests/nghttpx_spdy_test.go
View file @
7751f4fb
package
nghttp2
import
(
"encoding/json"
"github.com/tatsuhiro-t/spdy"
"golang.org/x/net/http2/hpack"
"net/http"
...
...
@@ -474,3 +475,114 @@ func TestS3H2RespPhaseReturn(t *testing.T) {
t
.
Errorf
(
"body = %v; want %v"
,
got
,
want
)
}
}
// TestS3APIBackendReplace exercise backend/replace API endpoint
// routine for successful case.
func
TestS3APIBackendReplace
(
t
*
testing
.
T
)
{
st
:=
newServerTesterTLSConnectPort
([]
string
{
"--npn-list=spdy/3.1"
,
"-f127.0.0.1,3010;api"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
t
.
Fatalf
(
"request should not be forwarded"
)
},
3010
)
defer
st
.
Close
()
res
,
err
:=
st
.
spdy
(
requestParam
{
name
:
"TestS3APIBackendReplace"
,
path
:
"/api/v1beta1/backend/replace"
,
method
:
"PUT"
,
body
:
[]
byte
(
`# comment
backend=127.0.0.1,3011
`
),
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.spdy() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"res.status: %v; want %v"
,
got
,
want
)
}
var
apiResp
APIResponse
err
=
json
.
Unmarshal
(
res
.
body
,
&
apiResp
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error unmarshaling API response: %v"
,
err
)
}
if
got
,
want
:=
apiResp
.
Status
,
"Success"
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
if
got
,
want
:=
apiResp
.
Code
,
200
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
}
// TestS3APIBackendReplaceBadMethod exercise backend/replace API
// endpoint routine with bad method.
func
TestS3APIBackendReplaceBadMethod
(
t
*
testing
.
T
)
{
st
:=
newServerTesterTLSConnectPort
([]
string
{
"--npn-list=spdy/3.1"
,
"-f127.0.0.1,3010;api"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
t
.
Fatalf
(
"request should not be forwarded"
)
},
3010
)
defer
st
.
Close
()
res
,
err
:=
st
.
spdy
(
requestParam
{
name
:
"TestS3APIBackendReplaceBadMethod"
,
path
:
"/api/v1beta1/backend/replace"
,
method
:
"GET"
,
body
:
[]
byte
(
`# comment
backend=127.0.0.1,3011
`
),
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.spdy() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
405
;
got
!=
want
{
t
.
Errorf
(
"res.status: %v; want %v"
,
got
,
want
)
}
var
apiResp
APIResponse
err
=
json
.
Unmarshal
(
res
.
body
,
&
apiResp
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error unmarshaling API response: %v"
,
err
)
}
if
got
,
want
:=
apiResp
.
Status
,
"Failure"
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
if
got
,
want
:=
apiResp
.
Code
,
405
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
}
// TestS3APINotFound exercise backend/replace API endpoint routine
// when API endpoint is not found.
func
TestS3APINotFound
(
t
*
testing
.
T
)
{
st
:=
newServerTesterTLSConnectPort
([]
string
{
"--npn-list=spdy/3.1"
,
"-f127.0.0.1,3010;api"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
t
.
Fatalf
(
"request should not be forwarded"
)
},
3010
)
defer
st
.
Close
()
res
,
err
:=
st
.
spdy
(
requestParam
{
name
:
"TestS3APINotFound"
,
path
:
"/api/notfound"
,
method
:
"GET"
,
body
:
[]
byte
(
`# comment
backend=127.0.0.1,3011
`
),
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.spdy() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
404
;
got
!=
want
{
t
.
Errorf
(
"res.status: %v; want %v"
,
got
,
want
)
}
var
apiResp
APIResponse
err
=
json
.
Unmarshal
(
res
.
body
,
&
apiResp
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error unmarshaling API response: %v"
,
err
)
}
if
got
,
want
:=
apiResp
.
Status
,
"Failure"
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
if
got
,
want
:=
apiResp
.
Code
,
404
;
got
!=
want
{
t
.
Errorf
(
"apiResp.Status: %v; want %v"
,
got
,
want
)
}
}
integration-tests/server_tester.go
View file @
7751f4fb
...
...
@@ -82,6 +82,10 @@ func newServerTesterTLS(args []string, t *testing.T, handler http.HandlerFunc) *
return
newServerTesterInternal
(
args
,
t
,
handler
,
true
,
serverPort
,
nil
)
}
func
newServerTesterTLSConnectPort
(
args
[]
string
,
t
*
testing
.
T
,
handler
http
.
HandlerFunc
,
port
int
)
*
serverTester
{
return
newServerTesterInternal
(
args
,
t
,
handler
,
true
,
port
,
nil
)
}
// newServerTester creates test context for TLS frontend connection
// with given clientConfig
func
newServerTesterTLSConfig
(
args
[]
string
,
t
*
testing
.
T
,
handler
http
.
HandlerFunc
,
clientConfig
*
tls
.
Config
)
*
serverTester
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment