Skip to content

Commit

Permalink
Test coverage improvements (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottBrenner authored Dec 25, 2023
1 parent 612f7ce commit c8cf14d
Showing 1 changed file with 25 additions and 4 deletions.
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")
}
}

0 comments on commit c8cf14d

Please sign in to comment.