From 3c6f10b158c2e9a6c2bac0bc8f3019730f118225 Mon Sep 17 00:00:00 2001 From: Scott Brenner Date: Mon, 25 Dec 2023 23:22:08 +0000 Subject: [PATCH 1/4] improvements --- cmd/download_test.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cmd/download_test.go b/cmd/download_test.go index b068b8c..5601640 100644 --- a/cmd/download_test.go +++ b/cmd/download_test.go @@ -3,7 +3,11 @@ Copyright © 2023 Scott Brenner */ package cmd -import "testing" +import ( + "io/ioutil" + "os" + "testing" +) func Test_openSourceFile(t *testing.T) { tests := []struct { @@ -11,7 +15,12 @@ func Test_openSourceFile(t *testing.T) { wantSourceURL string wantErr bool }{ - {"No such file", "", true}, + {"Success", "", false}, + {"Failure", "", true}, + } + err := ioutil.WriteFile("source.txt", []byte{}, 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 +32,7 @@ func Test_openSourceFile(t *testing.T) { if gotSourceURL != tt.wantSourceURL { t.Errorf("openSourceFile() = %v, want %v", gotSourceURL, tt.wantSourceURL) } + os.Remove("source.txt") }) } } @@ -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 := ioutil.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) { From b78afd53b0f2d0cdb42823b305b5e18af5dae58e Mon Sep 17 00:00:00 2001 From: Scott Brenner Date: Mon, 25 Dec 2023 23:25:25 +0000 Subject: [PATCH 2/4] improvements --- cmd/download_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/download_test.go b/cmd/download_test.go index 5601640..da213c4 100644 --- a/cmd/download_test.go +++ b/cmd/download_test.go @@ -47,6 +47,7 @@ func Test_downloadFromURL(t *testing.T) { wantErr bool }{ {"Valid", args{sourceURL: "https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfilecustom&simfileid=48669"}, false}, + {"Invalid", args{sourceURL: "https://zeninisher.com/invalid.zip"}, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -54,6 +55,7 @@ func Test_downloadFromURL(t *testing.T) { t.Errorf("downloadFromURL() error = %v, wantErr %v", err, tt.wantErr) } }) + os.Remove("pack.zip") } } From d01edcf9687de3ea330ae2a3f58a26b3d6be3899 Mon Sep 17 00:00:00 2001 From: Scott Brenner Date: Mon, 25 Dec 2023 23:43:12 +0000 Subject: [PATCH 3/4] improvements --- cmd/download_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/download_test.go b/cmd/download_test.go index da213c4..cd18cdf 100644 --- a/cmd/download_test.go +++ b/cmd/download_test.go @@ -15,10 +15,10 @@ func Test_openSourceFile(t *testing.T) { wantSourceURL string wantErr bool }{ - {"Success", "", false}, + {"Success", "https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid=8081", false}, {"Failure", "", true}, } - err := ioutil.WriteFile("source.txt", []byte{}, 0644) // Create a test file + err := ioutil.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) } @@ -46,7 +46,7 @@ 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 { @@ -101,13 +101,19 @@ func Test_downloadPack(t *testing.T) { name string wantErr bool }{ + {"Success", false}, {"No such file", true}, } + err := ioutil.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") } } From b1bc1db1423f76caa810ac12e1355c7761e800dd Mon Sep 17 00:00:00 2001 From: Scott Brenner Date: Mon, 25 Dec 2023 23:48:32 +0000 Subject: [PATCH 4/4] improvements --- cmd/download_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cmd/download_test.go b/cmd/download_test.go index cd18cdf..6cb8d31 100644 --- a/cmd/download_test.go +++ b/cmd/download_test.go @@ -4,7 +4,6 @@ Copyright © 2023 Scott Brenner package cmd import ( - "io/ioutil" "os" "testing" ) @@ -18,7 +17,7 @@ func Test_openSourceFile(t *testing.T) { {"Success", "https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid=8081", false}, {"Failure", "", true}, } - err := ioutil.WriteFile("source.txt", []byte("https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid=8081"), 0644) // Create a test file + 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) } @@ -47,7 +46,7 @@ func Test_downloadFromURL(t *testing.T) { wantErr bool }{ {"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}, + // {"Invalid", args{sourceURL: "https://zeninisher.com/invalid.zip"}, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -55,7 +54,6 @@ func Test_downloadFromURL(t *testing.T) { t.Errorf("downloadFromURL() error = %v, wantErr %v", err, tt.wantErr) } }) - os.Remove("pack.zip") } } @@ -83,7 +81,7 @@ func Test_removeZip(t *testing.T) { {"Delete after creation", false}, {"Fail to delete", true}, } - err := ioutil.WriteFile("pack.zip", []byte{}, 0644) // Create a test file + err := os.WriteFile("pack.zip", []byte{}, 0644) // Create a test file if err != nil { t.Fatal(err) } @@ -104,7 +102,7 @@ func Test_downloadPack(t *testing.T) { {"Success", false}, {"No such file", true}, } - err := ioutil.WriteFile("source.txt", []byte("https://zenius-i-vanisher.com/v5.2/download.php?type=ddrsimfile&simfileid=8081"), 0644) // Create a test file + 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) }