-
Couldn't load subscription status.
- Fork 87
PMM-1772 Use stable instances for tests. #34
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
Changes from all commits
5dd796d
affb60e
1eb19df
03a02d9
e5dd7ce
a324b5c
9468b6f
6ac7a57
727cfd8
c4e189b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
| /.idea/ | ||
| /.vscode/ | ||
| rds_exporter | ||
| config.yml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ build: | |
| tarball: | ||
| files: | ||
| - LICENSE | ||
| - config.yml | ||
| # - config.yml | ||
| crossbuild: | ||
| platforms: | ||
| - linux/amd64 | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| package basic | ||
|
|
||
| import ( | ||
| "sort" | ||
| "testing" | ||
|
|
||
| "github.com/percona/exporter_shared/helpers" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
|
|
@@ -13,47 +13,36 @@ import ( | |
| "github.com/percona/rds_exporter/sessions" | ||
| ) | ||
|
|
||
| func getCollector(t *testing.T) *Collector { | ||
| t.Helper() | ||
|
|
||
| func TestCollector(t *testing.T) { | ||
| cfg, err := config.Load("../config.tests.yml") | ||
| require.NoError(t, err) | ||
| client := client.New() | ||
| sess, err := sessions.New(cfg.Instances, client.HTTP(), false) | ||
| require.NoError(t, err) | ||
| return New(cfg, sess) | ||
| } | ||
|
|
||
| func TestCollector_Describe(t *testing.T) { | ||
| c := getCollector(t) | ||
| ch := make(chan *prometheus.Desc) | ||
| go func() { | ||
| c.Describe(ch) | ||
| close(ch) | ||
| }() | ||
|
|
||
| const expected = 50 | ||
| descs := make([]*prometheus.Desc, 0, expected) | ||
| for d := range ch { | ||
| descs = append(descs, d) | ||
| c := New(cfg, sess) | ||
|
|
||
| actualMetrics := helpers.ReadMetrics(helpers.CollectMetrics(c)) | ||
| sort.Slice(actualMetrics, func(i, j int) bool { return actualMetrics[i].Less(actualMetrics[j]) }) | ||
| actualLines := helpers.Format(helpers.WriteMetrics(actualMetrics)) | ||
|
|
||
| if *goldenTXT { | ||
| writeTestDataMetrics(t, actualLines) | ||
| } | ||
|
|
||
| assert.Equal(t, expected, len(descs), "%+v", descs) | ||
| } | ||
| for _, m := range actualMetrics { | ||
| m.Value = 0 | ||
| } | ||
| actualLines = helpers.Format(helpers.WriteMetrics(actualMetrics)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assignments should only be cuddled with other assignments (from |
||
|
|
||
| func TestCollector_Collect(t *testing.T) { | ||
| c := getCollector(t) | ||
| ch := make(chan prometheus.Metric) | ||
| go func() { | ||
| c.Collect(ch) | ||
| close(ch) | ||
| }() | ||
|
|
||
| const expected = 101 | ||
| metrics := make([]helpers.Metric, 0, expected) | ||
| for m := range ch { | ||
| metrics = append(metrics, *helpers.ReadMetric(m)) | ||
| expectedMetrics := helpers.ReadMetrics(helpers.Parse(readTestDataMetrics(t))) | ||
| sort.Slice(expectedMetrics, func(i, j int) bool { return expectedMetrics[i].Less(expectedMetrics[j]) }) | ||
| for _, m := range expectedMetrics { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only one cuddle assignment allowed before range statement (from |
||
| m.Value = 0 | ||
| } | ||
| expectedLines := helpers.Format(helpers.WriteMetrics(expectedMetrics)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assignments should only be cuddled with other assignments (from |
||
|
|
||
| assert.Equal(t, expected, len(metrics), "%+v", metrics) | ||
| // compare both to try to avoid go-difflib bug | ||
| assert.Equal(t, expectedLines, actualLines) | ||
| assert.Equal(t, expectedMetrics, actualMetrics) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package basic | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "flag" | ||
| "io/ioutil" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| var ( | ||
| golden = flag.Bool("golden", false, "does nothing; exists only for compatibility with other packages") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. var |
||
| goldenTXT = flag.Bool("golden-txt", false, "update golden .txt files") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. var |
||
| ) | ||
|
|
||
| func readTestDataMetrics(t *testing.T) []string { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. func |
||
| t.Helper() | ||
|
|
||
| b, err := ioutil.ReadFile(filepath.Join("testdata", "all.txt")) //nolint:gosec | ||
| require.NoError(t, err) | ||
| return strings.Split(string(bytes.TrimSpace(b)), "\n") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return statements should not be cuddled if block has more than two lines (from |
||
| } | ||
|
|
||
| func writeTestDataMetrics(t *testing.T, metrics []string) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. func |
||
| t.Helper() | ||
|
|
||
| b := []byte(strings.TrimSpace(strings.Join(metrics, "\n")) + "\n") | ||
| err := ioutil.WriteFile(filepath.Join("testdata", "all.txt"), b, 0666) | ||
| require.NoError(t, err) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func
TestCollectoris unused (fromunused)