mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 22:06:57 +00:00
add 3 integration-tests
This commit is contained in:
parent
bb8eb32ee2
commit
8e831db1e9
2 changed files with 87 additions and 0 deletions
|
@ -22,3 +22,19 @@ pipeline:
|
||||||
image: golang:1.18
|
image: golang:1.18
|
||||||
commands:
|
commands:
|
||||||
- go build
|
- go build
|
||||||
|
|
||||||
|
integration-tests:
|
||||||
|
image: golang:1.18
|
||||||
|
detach: true
|
||||||
|
commands:
|
||||||
|
- go run . --verbose &
|
||||||
|
- pid=$!
|
||||||
|
- sleep 10s
|
||||||
|
- cd integration && go test -tags integration ./...
|
||||||
|
- kill $pid
|
||||||
|
environment:
|
||||||
|
- ACME_API=https://acme.mock.directory
|
||||||
|
- ACME_ACCEPT_TERMS=true
|
||||||
|
- PAGES_DOMAIN=localhost.mock.directory
|
||||||
|
- RAW_DOMAIN=raw.localhost.mock.directory
|
||||||
|
- PORT=4430
|
||||||
|
|
71
integration/main_test.go
Normal file
71
integration/main_test.go
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
// //go:build integration
|
||||||
|
|
||||||
|
package integration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/cookiejar"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(t *testing.T) {
|
||||||
|
// if enableRunGitea() {
|
||||||
|
// p, err := runGitea()
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// defer func() {
|
||||||
|
// p.Kill()
|
||||||
|
// }()
|
||||||
|
// }
|
||||||
|
// log.Printf("testing with %v, %v, %v\n", getGiteaURL(), getGiteaUsername(), getGiteaPassword())
|
||||||
|
// exitCode := m.Run()
|
||||||
|
// os.Exit(exitCode)
|
||||||
|
|
||||||
|
// test custom domain redirect
|
||||||
|
resp, err := getTestHTTPSClient().Get("https://calciumdibromid.localhost.mock.directory:4430")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, http.StatusTemporaryRedirect, resp.StatusCode)
|
||||||
|
assert.EqualValues(t, "https://www.cabr2.de/", resp.Header["Location"][0])
|
||||||
|
assert.EqualValues(t, 0, getSize(resp.Body))
|
||||||
|
|
||||||
|
// test get image
|
||||||
|
resp, err = getTestHTTPSClient().Get("https://magiclike.localhost.mock.directory:4430/images/827679288a.jpg")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, http.StatusOK, resp.StatusCode)
|
||||||
|
assert.EqualValues(t, "image/jpeg", resp.Header["Content-Type"][0])
|
||||||
|
assert.EqualValues(t, "124635", resp.Header["Content-Length"][0])
|
||||||
|
assert.EqualValues(t, 124635, getSize(resp.Body))
|
||||||
|
|
||||||
|
// specify branch
|
||||||
|
resp, err = getTestHTTPSClient().Get("https://momar.localhost.mock.directory:4430/pag/@master/")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, http.StatusOK, resp.StatusCode)
|
||||||
|
assert.EqualValues(t, "text/html; charset=utf-8", resp.Header["Content-Type"][0])
|
||||||
|
assert.True(t, getSize(resp.Body) > 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTestHTTPSClient() *http.Client {
|
||||||
|
cookieJar, _ := cookiejar.New(nil)
|
||||||
|
return &http.Client{
|
||||||
|
Jar: cookieJar,
|
||||||
|
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
|
||||||
|
return http.ErrUseLastResponse
|
||||||
|
},
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSize(stream io.Reader) int {
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
buf.ReadFrom(stream)
|
||||||
|
return buf.Len()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue