diff --git a/linter_test.go b/linter_test.go index c32230a94..c14fbcc4c 100644 --- a/linter_test.go +++ b/linter_test.go @@ -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") diff --git a/project_test.go b/project_test.go index e3b4d2676..ad80a71da 100644 --- a/project_test.go +++ b/project_test.go @@ -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) + } } } diff --git a/testdata/config/projects/yml/.github/actionlint.yml b/testdata/config/projects/yml/.github/actionlint.yml new file mode 100644 index 000000000..2617efc68 --- /dev/null +++ b/testdata/config/projects/yml/.github/actionlint.yml @@ -0,0 +1,3 @@ +self-hosted-runner: + labels: [] +config-variables: null diff --git a/testdata/config/projects/yml/.github/workflows/test.yaml b/testdata/config/projects/yml/.github/workflows/test.yaml new file mode 100644 index 000000000..f1787617a --- /dev/null +++ b/testdata/config/projects/yml/.github/workflows/test.yaml @@ -0,0 +1,6 @@ +on: push +jobs: + test: + runs-on: ubuntu-latest + steps: + - run: echo