From 065378b7ecb554a822742d0198955af62f59eaea Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 26 Nov 2019 18:56:47 +0100 Subject: [PATCH 1/3] Replace asciilogo.txt with donwlodads index.html as a test resource --- arduino/resources/resources_test.go | 47 +++++++++++++++-------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/arduino/resources/resources_test.go b/arduino/resources/resources_test.go index 82404b30d54..5253f1f8aa1 100644 --- a/arduino/resources/resources_test.go +++ b/arduino/resources/resources_test.go @@ -20,6 +20,7 @@ package resources import ( "crypto" "encoding/hex" + "fmt" "net/http" "testing" @@ -31,16 +32,16 @@ func TestDownloadAndChecksums(t *testing.T) { tmp, err := paths.MkTempDir("", "") require.NoError(t, err) defer tmp.RemoveAll() - testFile := tmp.Join("cache", "asciilogo.txt") + testFile := tmp.Join("cache", "index.html") r := &DownloadResource{ - ArchiveFileName: "asciilogo.txt", + ArchiveFileName: "index.html", CachePath: "cache", - Checksum: "SHA-256:618d6c3d3f02388d4ddbe13c893902422a8656365b67ba19ef80873bf1da0f1f", + Checksum: "SHA-256:e021e1a223d03069d5f08dea25a58ca445a7376d9bdf980f756034f118449e66", Size: 2263, - URL: "https://arduino.cc/asciilogo.txt", + URL: "https://downloads.arduino.cc/index.html", } - digest, err := hex.DecodeString("618d6c3d3f02388d4ddbe13c893902422a8656365b67ba19ef80873bf1da0f1f") + digest, err := hex.DecodeString("e021e1a223d03069d5f08dea25a58ca445a7376d9bdf980f756034f118449e66") require.NoError(t, err) downloadAndTestChecksum := func() { @@ -51,29 +52,31 @@ func TestDownloadAndChecksums(t *testing.T) { data, err := testFile.ReadFile() require.NoError(t, err) + fmt.Println(string(data)) + fmt.Println("==========================================================================") algo := crypto.SHA256.New() algo.Write(data) require.EqualValues(t, digest, algo.Sum(nil)) } - // Normal download - downloadAndTestChecksum() - - // Download with cached file - d, err := r.Download(tmp, http.Header{}) - require.NoError(t, err) - require.Nil(t, d) - - // Download if cached file has data in excess (redownload) - data, err := testFile.ReadFile() - require.NoError(t, err) - data = append(data, []byte("123123123")...) - err = testFile.WriteFile(data) - require.NoError(t, err) + //// Normal download downloadAndTestChecksum() + // + //// Download with cached file + //d, err := r.Download(tmp, http.Header{}) + //require.NoError(t, err) + //require.Nil(t, d) + // + //// Download if cached file has data in excess (redownload) + //data, err := testFile.ReadFile() + //require.NoError(t, err) + //data = append(data, []byte("123123123")...) + //err = testFile.WriteFile(data) + //require.NoError(t, err) + //downloadAndTestChecksum() // Download if cached file has less data (resume) - data, err = testFile.ReadFile() + data, err := testFile.ReadFile() require.NoError(t, err) err = testFile.WriteFile(data[:1000]) require.NoError(t, err) @@ -91,12 +94,12 @@ func TestDownloadAndChecksums(t *testing.T) { _, err = r.TestLocalArchiveChecksum(tmp) require.Error(t, err) - r.Checksum = "SHA-1:960f50b4326ba28304039f3d2c0fb30a0463372f" + r.Checksum = "SHA-1:c007e47637cc6ad6176e7d94aeffc232ee34c1c1" res, err := r.TestLocalArchiveChecksum(tmp) require.NoError(t, err) require.True(t, res) - r.Checksum = "MD5:667cf48afcc12c38c8c1637947a04224" + r.Checksum = "MD5:2e388576eefd92a15967868d5f566f29" res, err = r.TestLocalArchiveChecksum(tmp) require.NoError(t, err) require.True(t, res) From 73821cc4b165d6e26edddcc38cf514df2ef0d94f Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 26 Nov 2019 18:59:13 +0100 Subject: [PATCH 2/3] Remove prints and re-enable test pieces --- arduino/resources/resources_test.go | 35 +++++++++++++---------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/arduino/resources/resources_test.go b/arduino/resources/resources_test.go index 5253f1f8aa1..f96c7e4d603 100644 --- a/arduino/resources/resources_test.go +++ b/arduino/resources/resources_test.go @@ -20,11 +20,10 @@ package resources import ( "crypto" "encoding/hex" - "fmt" "net/http" "testing" - paths "github.com/arduino/go-paths-helper" + "github.com/arduino/go-paths-helper" "github.com/stretchr/testify/require" ) @@ -52,32 +51,30 @@ func TestDownloadAndChecksums(t *testing.T) { data, err := testFile.ReadFile() require.NoError(t, err) - fmt.Println(string(data)) - fmt.Println("==========================================================================") algo := crypto.SHA256.New() algo.Write(data) require.EqualValues(t, digest, algo.Sum(nil)) } - //// Normal download + // Normal download downloadAndTestChecksum() - // - //// Download with cached file - //d, err := r.Download(tmp, http.Header{}) - //require.NoError(t, err) - //require.Nil(t, d) - // - //// Download if cached file has data in excess (redownload) - //data, err := testFile.ReadFile() - //require.NoError(t, err) - //data = append(data, []byte("123123123")...) - //err = testFile.WriteFile(data) - //require.NoError(t, err) - //downloadAndTestChecksum() - // Download if cached file has less data (resume) + // Download with cached file + d, err := r.Download(tmp, http.Header{}) + require.NoError(t, err) + require.Nil(t, d) + + // Download if cached file has data in excess (redownload) data, err := testFile.ReadFile() require.NoError(t, err) + data = append(data, []byte("123123123")...) + err = testFile.WriteFile(data) + require.NoError(t, err) + downloadAndTestChecksum() + + // Download if cached file has less data (resume) + data, err = testFile.ReadFile() + require.NoError(t, err) err = testFile.WriteFile(data[:1000]) require.NoError(t, err) downloadAndTestChecksum() From 68aeb69da867e01d0cded45ff11bee2c50952e5f Mon Sep 17 00:00:00 2001 From: Roberto Sora Date: Tue, 26 Nov 2019 19:05:57 +0100 Subject: [PATCH 3/3] Fix file size --- arduino/resources/resources_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino/resources/resources_test.go b/arduino/resources/resources_test.go index f96c7e4d603..7ba61ba5975 100644 --- a/arduino/resources/resources_test.go +++ b/arduino/resources/resources_test.go @@ -37,7 +37,7 @@ func TestDownloadAndChecksums(t *testing.T) { ArchiveFileName: "index.html", CachePath: "cache", Checksum: "SHA-256:e021e1a223d03069d5f08dea25a58ca445a7376d9bdf980f756034f118449e66", - Size: 2263, + Size: 1119, URL: "https://downloads.arduino.cc/index.html", } digest, err := hex.DecodeString("e021e1a223d03069d5f08dea25a58ca445a7376d9bdf980f756034f118449e66")