Skip to content

Commit

Permalink
Add more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Aug 27, 2024
1 parent 9dc7987 commit 0f7e6b8
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 22 deletions.
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 [email protected]
env GIT_COMMITTER_NAME=pint
env [email protected]
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 [email protected]
env GIT_COMMITTER_NAME=pint
env [email protected]
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

0 comments on commit 0f7e6b8

Please sign in to comment.