Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtodor committed Nov 7, 2024
1 parent e73ad7d commit ffbbc74
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cmd/flakechecker/flake_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"github.com/stretchr/testify/assert"
"regexp"
"testing"
)

func TestLoadFlakeConfigFile(t *testing.T) {
samples := []struct {
name string
fileName string

expectError bool
expectConfig []*flakeCheckerRecord
}{
{
name: "no config file",
fileName: "no_config.json",
expectError: true,
expectConfig: nil,
},
{
name: "valid config file",
fileName: "testdata/flake-config.json",
expectError: false,
expectConfig: []*flakeCheckerRecord{
{
MatchJobName: "pr-.*",
RatioJobName: "main-branch-tests",
TestNameRegex: "TestLoadFlakeConf.*",
Classname: "TestLoadFlakeConfigFile",
RatioThreshold: 5,
regexMatchJobName: regexp.MustCompile("pr-.*"),
regexTestNameRegex: regexp.MustCompile("TestLoadFlakeConf.*"),
},
{
MatchJobName: "pull-request-tests",
RatioJobName: "main-branch-tests",
TestNameRegex: "TestLoadFlakeConfigFile",
Classname: "TestLoadFlakeConfigFile",
RatioThreshold: 10,
regexMatchJobName: regexp.MustCompile("pull-request-tests"),
regexTestNameRegex: regexp.MustCompile("TestLoadFlakeConfigFile"),
},
},
},
}

for _, sample := range samples {
t.Run(sample.name, func(tt *testing.T) {
config, err := loadFlakeConfigFile(sample.fileName)

assert.Equal(tt, sample.expectError, err != nil)
assert.Equal(tt, sample.expectConfig, config)
})
}
}
18 changes: 18 additions & 0 deletions cmd/flakechecker/testdata/flake-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"_comment": "Config with regex",
"match_job_name": "pr-.*",
"ratio_job_name": "main-branch-tests",
"test_name_regex": "TestLoadFlakeConf.*",
"classname": "TestLoadFlakeConfigFile",
"ratio_threshold": 5
},
{
"_comment": "Config with flat values",
"match_job_name": "pull-request-tests",
"ratio_job_name": "main-branch-tests",
"test_name_regex": "TestLoadFlakeConfigFile",
"classname": "TestLoadFlakeConfigFile",
"ratio_threshold": 10
}
]

0 comments on commit ffbbc74

Please sign in to comment.