Add testhlper.go, a tool for helping with tests
In this case all it does is retrieves verification codes
This commit is contained in:
parent
e752e32825
commit
ac5b78b752
3 changed files with 50 additions and 0 deletions
|
@ -13,3 +13,15 @@ build:signal-server:
|
||||||
- docker push ${CI_REGISTRY_IMAGE}/signal-server:${CI_COMMIT_REF_SLUG}
|
- docker push ${CI_REGISTRY_IMAGE}/signal-server:${CI_COMMIT_REF_SLUG}
|
||||||
- docker push ${CI_REGISTRY_IMAGE}/signal-server:${VERSION}
|
- docker push ${CI_REGISTRY_IMAGE}/signal-server:${VERSION}
|
||||||
- echo "docker pull ${CI_REGISTRY_IMAGE}/signal-server:${VERSION}"
|
- echo "docker pull ${CI_REGISTRY_IMAGE}/signal-server:${VERSION}"
|
||||||
|
|
||||||
|
build:testhelper:
|
||||||
|
tags:
|
||||||
|
- docker-builder
|
||||||
|
image: docker:latest
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
|
||||||
|
- docker build -f testhelper.Dockerfile -t ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_SHA:0:8} .
|
||||||
|
- docker tag ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_SHA:0:8} ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_REF_SLUG}
|
||||||
|
- docker push ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_SHA:0:8}
|
||||||
|
- docker push ${CI_REGISTRY_IMAGE}/testhelper:${CI_COMMIT_REF_SLUG}
|
||||||
|
|
7
testhelper.Dockerfile
Normal file
7
testhelper.Dockerfile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
FROM golang:latest
|
||||||
|
COPY testhelper.go /
|
||||||
|
RUN go build testhelper.go
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=build /testhelper /testhelper
|
||||||
|
ENTRYPOINT ["/testhelper"]
|
31
testhelper.go
Normal file
31
testhelper.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package main;
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
// "golang.org/x/net/html"
|
||||||
|
"database/sql"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
"os"
|
||||||
|
"log"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func crash(err error) {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
db, err := sql.Open("postgres", os.Getenv("DB"))
|
||||||
|
crash(err)
|
||||||
|
|
||||||
|
http.HandleFunc("/verification-code", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
account := r.PostFormValue("account")
|
||||||
|
var code string
|
||||||
|
err := db.QueryRow("SELECT verification_code FROM pending_accounts WHERE number = $1", account).Scan(&code)
|
||||||
|
crash(err)
|
||||||
|
fmt.Fprintf(w, "%s\n", code)
|
||||||
|
})
|
||||||
|
log.Fatal(http.ListenAndServe(":8082", nil))
|
||||||
|
}
|
Loading…
Reference in a new issue