Skip to content

Commit

Permalink
Add more ci checks
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Jan 7, 2022
1 parent e532f55 commit 9ff11ec
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions cmd/pint/tests/0031_ci_bitbucket.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
exec bash -x ./webserver.sh &
exec bash -c 'while [ ! -f server.pid ]; do sleep 1 ; done'

mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

cp ../src/v1.yml rules.yml
cp ../src/.pint.hcl .
env GIT_AUTHOR_NAME=pint
env GIT_AUTHOR_EMAIL=pint@example.com
env GIT_COMMITTER_NAME=pint
env GIT_COMMITTER_EMAIL=pint@example.com
exec git add .
exec git commit -am 'import rules and config'

exec git checkout -b v2
cp ../src/v2.yml rules.yml
exec git commit -am 'v2'

env BITBUCKET_AUTH_TOKEN="12345"
pint.ok -l debug --no-color ci
! stdout .
stderr 'level=debug msg="Sending a request to BitBucket" method=PUT'
stderr 'level=debug msg="BitBucket request completed" status=200'
stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE'
stderr 'level=debug msg="BitBucket request completed" status=200'
exec sh -c 'cat ../server.pid | xargs kill'

-- src/v1.yml --
- alert: rule1
expr: sum(foo) by(job)
- alert: rule2
expr: sum(foo) by(job)
for: 0s

-- src/v2.yml --
- alert: rule1
expr: sum(foo) by(job)
for: 0s
- alert: rule2
expr: sum(foo) by(job)
for: 0s

-- src/.pint.hcl --
ci {
baseBranch = "main"
}
repository {
bitbucket {
uri = "http://127.0.0.1:8080"
timeout = "10s"
project = "prometheus"
repository = "rules"
}
}

-- webserver.go --
package main

import (
"context"
"io"
"log"
"net"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "OK")
})

listener, err := net.Listen("tcp", "127.0.0.1:8080")
if err != nil {
log.Fatal(err)
}

server := &http.Server{
Addr: "127.0.0.1:8080",
}

go func() {
_ = server.Serve(listener)
}()

pid := os.Getpid()
err = os.WriteFile("server.pid", []byte(strconv.Itoa(pid)), 0644)
if err != nil {
log.Fatal(err)
}

stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-stop
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)
}

-- webserver.sh --
env GOCACHE=$TMPDIR go run webserver.go

0 comments on commit 9ff11ec

Please sign in to comment.