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

Test coverage improvements #5

Merged
merged 4 commits into from
Dec 25, 2023
Merged
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
29 changes: 25 additions & 4 deletions cmd/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ Copyright © 2023 Scott Brenner <[email protected]>
*/
package cmd

import "testing"
import (
"os"
"testing"
)

func Test_openSourceFile(t *testing.T) {
tests := []struct {
name string
wantSourceURL string
wantErr bool
}{
{"No such file", "", true},
{"Success", "https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid=8081", false},
{"Failure", "", true},
}
err := os.WriteFile("source.txt", []byte("https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid=8081"), 0644) // Create a test file
if err != nil {
t.Fatal(err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -23,6 +31,7 @@ func Test_openSourceFile(t *testing.T) {
if gotSourceURL != tt.wantSourceURL {
t.Errorf("openSourceFile() = %v, want %v", gotSourceURL, tt.wantSourceURL)
}
os.Remove("source.txt")
})
}
}
Expand All @@ -36,7 +45,8 @@ func Test_downloadFromURL(t *testing.T) {
args args
wantErr bool
}{
{"Valid", args{sourceURL: "https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfilecustom&simfileid=48669"}, false},
{"Valid", args{sourceURL: "https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid=8081"}, false},
// {"Invalid", args{sourceURL: "https://zeninisher.com/invalid.zip"}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -68,7 +78,12 @@ func Test_removeZip(t *testing.T) {
name string
wantErr bool
}{
{"Success", false},
{"Delete after creation", false},
{"Fail to delete", true},
}
err := os.WriteFile("pack.zip", []byte{}, 0644) // Create a test file
if err != nil {
t.Fatal(err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -84,13 +99,19 @@ func Test_downloadPack(t *testing.T) {
name string
wantErr bool
}{
{"Success", false},
{"No such file", true},
}
err := os.WriteFile("source.txt", []byte("https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid=8081"), 0644) // Create a test file
if err != nil {
t.Fatal(err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := downloadPack(); (err != nil) != tt.wantErr {
t.Errorf("downloadPack() error = %v, wantErr %v", err, tt.wantErr)
}
})
os.Remove("source.txt")
}
}