generated from microsoft/vscode-remote-try-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
612f7ce
commit c8cf14d
Showing
1 changed file
with
25 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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") | ||
}) | ||
} | ||
} | ||
|
@@ -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) { | ||
|
@@ -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) { | ||
|
@@ -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") | ||
} | ||
} |