Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca50d22

Browse filesBrowse files
committed
fix test and error handling
1 parent 2d8fa5d commit ca50d22
Copy full SHA for ca50d22

2 files changed

+27-4Lines changed: 27 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/dbc/init.go‎

Copy file name to clipboardExpand all lines: cmd/dbc/init.go
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func (m initModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6767
switch msg := msg.(type) {
6868
case error:
6969
m.status = 1
70-
tea.Println("Error:", msg.Error())
71-
return m, tea.Quit
70+
return m, tea.Sequence(
71+
tea.Println("Error: ", msg.Error()), tea.Quit)
7272
}
73-
return m, tea.Quit
73+
return m, nil
7474
}
7575

7676
func (m initModel) View() string { return "" }
Collapse file

‎cmd/dbc/init_test.go‎

Copy file name to clipboardExpand all lines: cmd/dbc/init_test.go
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18+
func TestAlreadyExists(t *testing.T) {
19+
dir := t.TempDir()
20+
filePath := filepath.Join(dir, "dbc.toml")
21+
22+
// Create the file to simulate it already existing
23+
require.NoError(t, os.WriteFile(filePath, []byte("existing content"), 0644))
24+
t.Cleanup(func() {
25+
os.Remove(filePath)
26+
})
27+
m := InitCmd{Path: filePath}.GetModel()
28+
29+
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
30+
defer cancel()
31+
32+
var out bytes.Buffer
33+
p := tea.NewProgram(m, tea.WithInput(nil), tea.WithOutput(&out),
34+
tea.WithContext(ctx))
35+
36+
_, err := p.Run()
37+
require.NoError(t, err)
38+
assert.Contains(t, out.String(), "dbc.toml already exists")
39+
}
40+
1841
func TestInit(t *testing.T) {
1942
dir := t.TempDir()
2043

@@ -40,7 +63,7 @@ func TestInit(t *testing.T) {
4063
t.Run(tt.name, func(t *testing.T) {
4164
m := InitCmd{Path: tt.path}.GetModel()
4265

43-
ctx, cancel := context.WithTimeout(t.Context(), 50*time.Second)
66+
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
4467
defer cancel()
4568

4669
var out bytes.Buffer

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.