-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli_test.go
More file actions
85 lines (75 loc) · 1.81 KB
/
cli_test.go
File metadata and controls
85 lines (75 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"os"
"path/filepath"
"testing"
"github.com/spf13/cobra"
)
func TestLoadReleaseNotes(t *testing.T) {
t.Run("from inline string", func(t *testing.T) {
got, err := loadReleaseNotes("My notes", "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != "My notes" {
t.Errorf("got %q", got)
}
})
t.Run("from file overrides inline", func(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "notes.txt")
_ = os.WriteFile(filePath, []byte("file content"), 0o644)
got, err := loadReleaseNotes("inline content", filePath)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != "file content" {
t.Errorf("got %q, want file content", got)
}
})
t.Run("from file when inline is empty", func(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "notes.txt")
_ = os.WriteFile(filePath, []byte("notes from file"), 0o644)
got, err := loadReleaseNotes("", filePath)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != "notes from file" {
t.Errorf("got %q", got)
}
})
t.Run("missing file returns error", func(t *testing.T) {
_, err := loadReleaseNotes("", "/nonexistent/notes.txt")
if err == nil {
t.Fatal("expected error")
}
})
t.Run("neither notes nor file returns error", func(t *testing.T) {
_, err := loadReleaseNotes("", "")
if err == nil {
t.Fatal("expected error")
}
})
}
func TestCommandBuilders(t *testing.T) {
builders := []func() *cobra.Command{
dumpVersionsCmd,
addVersionCmd,
dumpProductCmd,
listProductsCmd,
updateProductCmd,
cloneProductCmd,
releaseCmd,
}
for _, b := range builders {
cmd := b()
if cmd == nil {
t.Errorf("%T returned nil", b)
continue
}
if cmd.Use == "" {
t.Errorf("command has empty Use field")
}
}
}