Skip to content

Commit ec6ec44

Browse files
committed
fix(labels): write tests and fix loop logic
1 parent b5a7243 commit ec6ec44

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

internal/cmd/inputs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"slices"
77
)
88

9-
var errIgnoreLabelsConflict = errors.New("--ignore-labels contains a value which conflicts with --labels")
9+
var errLabelsConflict = errors.New("--ignore-labels contains a value which conflicts with --labels")
1010

1111
// validateInputs checks if the provided inputs are valid
1212
func ValidateInputs(args []string) error {
1313
if err := ValidateLabels(selectLabels, ignoreLabels); err != nil {
14+
return err
1415
}
1516

1617
// If no args and no file, we can't proceed
@@ -32,7 +33,7 @@ func ValidateLabels(selectLabels []string, ignoreLabels []string) error {
3233
// Check for conflicts between ignoreLabels and selectLabels
3334
for _, ignoreL := range ignoreLabels {
3435
if i := slices.Index(selectLabels, ignoreL); i != -1 {
35-
return fmt.Errorf("%w: %q %q", errIgnoreLabelsConflict, ignoreLabels[i], selectLabels)
36+
return fmt.Errorf("%w: %q %q", errLabelsConflict, selectLabels[i], ignoreLabels)
3637
}
3738
}
3839

internal/cmd/inputs_test.go

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,53 @@
11
package cmd
22

33
import (
4-
"bytes"
5-
"log/slog"
4+
"errors"
65
"os"
76
"testing"
87
)
98

9+
func TestValidateLabels(t *testing.T) {
10+
t.Parallel()
11+
12+
tests := []struct {
13+
selectLabels []string
14+
ignoreLabels []string
15+
want error
16+
}{
17+
{
18+
want: nil,
19+
},
20+
{
21+
selectLabels: []string{"a"},
22+
ignoreLabels: []string{"b"},
23+
want: nil,
24+
},
25+
{
26+
selectLabels: []string{"a"},
27+
ignoreLabels: []string{"a", "b"},
28+
want: errLabelsConflict,
29+
},
30+
{
31+
selectLabels: []string{"a", "b"},
32+
ignoreLabels: []string{"b"},
33+
want: errLabelsConflict,
34+
},
35+
}
36+
37+
for _, test := range tests {
38+
t.Run("", func(t *testing.T) {
39+
t.Parallel()
40+
41+
got := ValidateLabels(test.selectLabels, test.ignoreLabels)
42+
43+
if !errors.Is(got, test.want) {
44+
t.Fatalf("want %s, but go %s", test.want, got)
45+
}
46+
})
47+
}
48+
}
49+
50+
/*
1051
// mockLogger creates a test logger that writes to a bytes.Buffer
1152
func setupMockLogger() (*bytes.Buffer, func()) {
1253
var buf bytes.Buffer
@@ -18,7 +59,6 @@ func setupMockLogger() (*bytes.Buffer, func()) {
1859
}
1960
}
2061
21-
/*
2262
func TestValidateInputs_NoReposSpecified(t *testing.T) {
2363
// Save original values
2464
origReposFile := reposFile

0 commit comments

Comments
 (0)