Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for pint ci with no changes #1090

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions cmd/pint/tests/0188_ci_noop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
http response bitbucket /rest/insights/1.0/projects/prometheus/repos/rules/commits/.*/reports/pint 200 OK
http response bitbucket /rest/api/1.0/projects/prometheus/repos/rules/commits/.*/pull-requests 200 {}
http start bitbucket 127.0.0.1:6188

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

cp ../src/rules.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
exec touch .keep
exec git add .keep
exec git commit -am 'v2'

env BITBUCKET_AUTH_TOKEN="12345"
exec pint -l debug --no-color ci
! stdout .
stderr '{"value":2,"title":"Number of rules parsed","type":"NUMBER"}'
stderr '{"value":2,"title":"Number of rules checked","type":"NUMBER"}'
stderr '{"value":0,"title":"Number of problems found","type":"NUMBER"}'
stderr '{"value":0,"title":"Number of offline checks","type":"NUMBER"}'
stderr '{"value":0,"title":"Number of online checks","type":"NUMBER"}'

-- src/rules.yml --
- alert: alert1
expr: up == 0
for: 5m
- alert: alert2
expr: up == 0
for: 5m

-- src/.pint.hcl --
parser {
relaxed = [".*"]
}
ci {
baseBranch = "main"
}
repository {
bitbucket {
uri = "http://127.0.0.1:6188"
project = "prometheus"
repository = "rules"
}
}
prometheus "prom" {
uri = "http://127.0.0.1:2188"
timeout = "5s"
required = true
}
rule {
match {
kind = "alerting"
}
alerts {
range = "1d"
step = "1m"
resolve = "5m"
}
}
7 changes: 7 additions & 0 deletions cmd/pint/tests/0189_config_bad_loglevel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
! exec pint -l invalid --no-color config
! stdout .
stderr 'ERROR Fatal error err="failed to set log level: ''invalid'' is not a valid log level"'

! exec pint -l invalid --no-color parse 'foo'
! stdout .
stderr 'ERROR Fatal error err="failed to set log level: ''invalid'' is not a valid log level"'
38 changes: 38 additions & 0 deletions cmd/pint/tests/0190_ci_dup_prom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

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
exec touch .keep
exec git add .keep
exec git commit -am 'v2'

! exec pint --no-color ci
! stdout .
cmp stderr ../stderr.txt

-- stderr.txt --
level=INFO msg="Loading configuration file" path=.pint.hcl
level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": prometheus server name must be unique, found two or more config blocks using \"prom\" name"
-- src/.pint.hcl --
ci {
baseBranch = "main"
}
prometheus "prom" {
uri = "http://127.0.0.1:2190"
timeout = "5s"
required = true
}
prometheus "prom" {
uri = "http://127.0.0.1:3190"
timeout = "5s"
required = true
}
19 changes: 19 additions & 0 deletions cmd/pint/tests/0191_lint_dup_prom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
! exec pint --no-color lint rules.yml
! stdout .
cmp stderr stderr.txt

-- stderr.txt --
level=INFO msg="Loading configuration file" path=.pint.hcl
level=ERROR msg="Fatal error" err="failed to load config file \".pint.hcl\": prometheus server name must be unique, found two or more config blocks using \"prom\" name"
-- rules.yml --
-- .pint.hcl --
prometheus "prom" {
uri = "http://127.0.0.1:2191"
timeout = "5s"
required = true
}
prometheus "prom" {
uri = "http://127.0.0.1:3191"
timeout = "5s"
required = true
}
40 changes: 40 additions & 0 deletions cmd/pint/tests/0192_ci_broken_removed_rule.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

cp ../src/rules.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
exec git rm rules.yml
exec git commit -am 'v2'

exec pint --no-color ci
! stdout .
cmp stderr ../stderr.txt

-- stderr.txt --
level=INFO msg="Loading configuration file" path=.pint.hcl
level=INFO msg="Finding all rules to check on current git branch" base=main
-- src/rules.yml --
groups:
- name: foo
rules:
- record:
expr: sum(foo) by(job)
- record: rule2
expr: sum(foo

-- src/.pint.hcl --
ci {
baseBranch = "main"
}
parser {
include = ["rules.yml"]
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ require (
go.uber.org/atomic v1.11.0
go.uber.org/automaxprocs v1.5.3
go.uber.org/ratelimit v0.3.1
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/oauth2 v0.22.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -72,6 +71,7 @@ require (
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions internal/checks/alerts_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package checks
import (
"context"
"fmt"
"slices"
"strconv"
"strings"

"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/parser"

"golang.org/x/exp/slices"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/alerts_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"strings"
textTemplate "text/template"
"text/template/parse"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/prometheus/prometheus/promql"
promParser "github.com/prometheus/prometheus/promql/parser"
promTemplate "github.com/prometheus/prometheus/template"
"golang.org/x/exp/slices"

"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/parser"
Expand Down
3 changes: 1 addition & 2 deletions internal/checks/promql_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package checks
import (
"context"
"fmt"
"slices"
"time"

"golang.org/x/exp/slices"

"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/output"
"github.com/cloudflare/pint/internal/parser"
Expand Down
3 changes: 1 addition & 2 deletions internal/checks/promql_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"fmt"
"log/slog"
"regexp"
"slices"
"strconv"
"strings"
"time"

"golang.org/x/exp/slices"

"github.com/cloudflare/pint/internal/comments"
"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/output"
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_vector_matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package checks
import (
"context"
"fmt"
"slices"
"sort"
"strings"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
promParser "github.com/prometheus/prometheus/promql/parser"
"golang.org/x/exp/slices"

"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/parser"
Expand Down
3 changes: 1 addition & 2 deletions internal/checks/rule_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"net/http"
"net/url"
"regexp"
"slices"
"time"

"golang.org/x/exp/slices"

"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/parser"
)
Expand Down
3 changes: 1 addition & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"fmt"
"log/slog"
"os"
"slices"
"strings"
"time"

"golang.org/x/exp/slices"

"github.com/zclconf/go-cty/cty"

"github.com/cloudflare/pint/internal/checks"
Expand Down
3 changes: 1 addition & 2 deletions internal/config/parsed_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package config

import (
"context"
"slices"
"time"

"golang.org/x/exp/slices"

"github.com/cloudflare/pint/internal/checks"
"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/promapi"
Expand Down
3 changes: 1 addition & 2 deletions internal/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"fmt"
"io"
"log/slog"
"slices"
"time"

"golang.org/x/exp/slices"

"github.com/cloudflare/pint/internal/comments"
"github.com/cloudflare/pint/internal/parser"
)
Expand Down
3 changes: 1 addition & 2 deletions internal/discovery/git_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"bytes"
"fmt"
"log/slog"
"slices"
"sort"
"strings"

"golang.org/x/exp/slices"

"github.com/cloudflare/pint/internal/git"
"github.com/cloudflare/pint/internal/output"
"github.com/cloudflare/pint/internal/parser"
Expand Down
3 changes: 1 addition & 2 deletions internal/git/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"log/slog"
"os"
"path"
"slices"
"strings"

"golang.org/x/exp/slices"
)

type FileStatus rune
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package parser

import (
"fmt"
"slices"
"strconv"
"strings"

"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"

"github.com/cloudflare/pint/internal/comments"
Expand Down
Loading