Skip to content

Commit

Permalink
test detecting config file already existing before generating new one
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Nov 2, 2024
1 parent a93bb53 commit c270d66
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
22 changes: 22 additions & 0 deletions linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,28 @@ func TestLinterRemoveRuleOnRulesCreatedHook(t *testing.T) {
}
}

func TestLinterGenerateDefaultConfigAlreadyExists(t *testing.T) {
l, err := NewLinter(io.Discard, &LinterOptions{})
if err != nil {
t.Fatal(err)
}

for _, n := range []string{"ok", "yml"} {
d := filepath.Join("testdata", "config", "projects", n)
testEnsureDotGitDir(d)

err := l.GenerateDefaultConfig(d)
if err == nil {
t.Fatal("error did not occur for project", d)
}
want := "config file already exists at"
msg := err.Error()
if !strings.Contains(msg, want) {
t.Fatalf("error message %q does not contain expected text %q", msg, want)
}
}
}

func BenchmarkLintWorkflowFiles(b *testing.B) {
large := filepath.Join("testdata", "bench", "many_scripts.yaml")
small := filepath.Join("testdata", "bench", "small.yaml")
Expand Down
28 changes: 15 additions & 13 deletions project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,21 @@ func TestProjectsDoesNotFindProjectFromOutside(t *testing.T) {
}
}

func TestProjectsLoadingProjectConfig(t *testing.T) {
d := filepath.Join("testdata", "config", "projects", "ok")
testEnsureDotGitDir(d)
ps := NewProjects()
p, err := ps.At(d)
if err != nil {
t.Fatal(err)
}
if p == nil {
t.Fatal("project was not found at", d)
}
if c := p.Config(); c == nil {
t.Fatal("config was not found for directory", d)
func TestProjectsLoadProjectConfig(t *testing.T) {
for _, n := range []string{"ok", "yml"} {
d := filepath.Join("testdata", "config", "projects", n)
testEnsureDotGitDir(d)
ps := NewProjects()
p, err := ps.At(d)
if err != nil {
t.Fatal(err)
}
if p == nil {
t.Fatal("project was not found at", d)
}
if c := p.Config(); c == nil {
t.Fatal("config was not found for directory", d)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions testdata/config/projects/yml/.github/actionlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
self-hosted-runner:
labels: []
config-variables: null
6 changes: 6 additions & 0 deletions testdata/config/projects/yml/.github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo

0 comments on commit c270d66

Please sign in to comment.