File tree Expand file tree Collapse file tree
Open diff view settings
Expand file tree Collapse file tree
Open diff view settings
Original file line number Diff line number Diff 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
7676func (m initModel ) View () string { return "" }
Original file line number Diff line number Diff 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+
1841func 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
You can’t perform that action at this time.
0 commit comments