Skip to content

Commit c270d66

Browse files
committed
test detecting config file already existing before generating new one
1 parent a93bb53 commit c270d66

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

linter_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,28 @@ func TestLinterRemoveRuleOnRulesCreatedHook(t *testing.T) {
634634
}
635635
}
636636

637+
func TestLinterGenerateDefaultConfigAlreadyExists(t *testing.T) {
638+
l, err := NewLinter(io.Discard, &LinterOptions{})
639+
if err != nil {
640+
t.Fatal(err)
641+
}
642+
643+
for _, n := range []string{"ok", "yml"} {
644+
d := filepath.Join("testdata", "config", "projects", n)
645+
testEnsureDotGitDir(d)
646+
647+
err := l.GenerateDefaultConfig(d)
648+
if err == nil {
649+
t.Fatal("error did not occur for project", d)
650+
}
651+
want := "config file already exists at"
652+
msg := err.Error()
653+
if !strings.Contains(msg, want) {
654+
t.Fatalf("error message %q does not contain expected text %q", msg, want)
655+
}
656+
}
657+
}
658+
637659
func BenchmarkLintWorkflowFiles(b *testing.B) {
638660
large := filepath.Join("testdata", "bench", "many_scripts.yaml")
639661
small := filepath.Join("testdata", "bench", "small.yaml")

project_test.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,21 @@ func TestProjectsDoesNotFindProjectFromOutside(t *testing.T) {
9999
}
100100
}
101101

102-
func TestProjectsLoadingProjectConfig(t *testing.T) {
103-
d := filepath.Join("testdata", "config", "projects", "ok")
104-
testEnsureDotGitDir(d)
105-
ps := NewProjects()
106-
p, err := ps.At(d)
107-
if err != nil {
108-
t.Fatal(err)
109-
}
110-
if p == nil {
111-
t.Fatal("project was not found at", d)
112-
}
113-
if c := p.Config(); c == nil {
114-
t.Fatal("config was not found for directory", d)
102+
func TestProjectsLoadProjectConfig(t *testing.T) {
103+
for _, n := range []string{"ok", "yml"} {
104+
d := filepath.Join("testdata", "config", "projects", n)
105+
testEnsureDotGitDir(d)
106+
ps := NewProjects()
107+
p, err := ps.At(d)
108+
if err != nil {
109+
t.Fatal(err)
110+
}
111+
if p == nil {
112+
t.Fatal("project was not found at", d)
113+
}
114+
if c := p.Config(); c == nil {
115+
t.Fatal("config was not found for directory", d)
116+
}
115117
}
116118
}
117119

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
self-hosted-runner:
2+
labels: []
3+
config-variables: null
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
on: push
2+
jobs:
3+
test:
4+
runs-on: ubuntu-latest
5+
steps:
6+
- run: echo

0 commit comments

Comments
 (0)