Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qodo Cover Update: 1736899139 #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions templated_tests/go/taskmgr/internal/cli/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ func TestParseArgs(t *testing.T) {
t.Errorf("Expected args ['MyTask'], got %v", rest)
}
}

func TestParseArgsEmptyInput(t *testing.T) {
cmd, rest := ParseArgs([]string{})
if cmd != "" {
t.Errorf("Expected cmd '', got '%s'", cmd)
}
if rest != nil {
t.Errorf("Expected args nil, got %v", rest)
}
}

68 changes: 68 additions & 0 deletions templated_tests/go/taskmgr/internal/tasks/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,71 @@ func TestFileStore(t *testing.T) {
t.Errorf("Expected persisted 'Updated' task, got %v", list)
}
}

func TestFileStoreRemoveInvalidIndex(t *testing.T) {
dir, err := ioutil.TempDir("", "taskmgr_test")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(dir)

testFile := filepath.Join(dir, "tasks.json")
store := NewFileStore(testFile)

// Add a task to ensure the file is created
if err := store.Add(Task{Title: "Example"}); err != nil {
t.Fatalf("Add returned an error: %v", err)
}

err = store.Remove(1) // Invalid index
if err == nil {
t.Error("Expected error when removing task at invalid index, got nil")
}
}


func TestFileStoreListInvalidJSON(t *testing.T) {
dir, err := ioutil.TempDir("", "taskmgr_test")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(dir)

testFile := filepath.Join(dir, "tasks.json")
store := NewFileStore(testFile)

// Create a file with invalid JSON
err = ioutil.WriteFile(testFile, []byte("{invalid json"), 0644)
if err != nil {
t.Fatalf("Failed to write to test file: %v", err)
}

list := store.List()
if len(list) != 0 {
t.Errorf("Expected empty list due to invalid JSON, got %d tasks", len(list))
}
}


func TestFileStoreAddReadError(t *testing.T) {
dir, err := ioutil.TempDir("", "taskmgr_test")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(dir)

testFile := filepath.Join(dir, "tasks.json")
store := NewFileStore(testFile)

// Create a file with invalid JSON to simulate a read error
err = ioutil.WriteFile(testFile, []byte("{invalid json"), 0644)
if err != nil {
t.Fatalf("Failed to write to test file: %v", err)
}

err = store.Add(Task{Title: "Example"})
if err == nil {
t.Error("Expected error when adding task due to read error, got nil")
}
}