dl/dl_test.go

35 lines
7.0 KiB
Go
Raw Normal View History

package dl
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
var dlResp = []byte(`[{"version":"go1.16.7","stable":true,"files":[{"filename":"go1.16.7.src.tar.gz","os":"","arch":"","version":"go1.16.7","sha256":"1a9f2894d3d878729f7045072f30becebe243524cf2fce4e0a7b248b1e0654ac","size":20922206,"kind":"source"},{"filename":"go1.16.7.darwin-amd64.tar.gz","os":"darwin","arch":"amd64","version":"go1.16.7","sha256":"8018bf556e833912d455fab7ea279caa542239b6675c6b3861e9002380c70080","size":130203260,"kind":"archive"},{"filename":"go1.16.7.darwin-amd64.pkg","os":"darwin","arch":"amd64","version":"go1.16.7","sha256":"24e95aa60f516cfc34139cfd1192efe97724ea62ab36ad9404df36b926b1f879","size":130588410,"kind":"installer"},{"filename":"go1.16.7.darwin-arm64.tar.gz","os":"darwin","arch":"arm64","version":"go1.16.7","sha256":"7721706560d6a17b80b1f68efc0ebef27028bd51547127362ae0c0dac287b24b","size":125703153,"kind":"archive"},{"filename":"go1.16.7.darwin-arm64.pkg","os":"darwin","arch":"arm64","version":"go1.16.7","sha256":"c0924334dec1b39226af6ac8c63473b4f9e7689bd9837fdd5e1508d9a831fae1","size":126064386,"kind":"installer"},{"filename":"go1.16.7.freebsd-386.tar.gz","os":"freebsd","arch":"386","version":"go1.16.7","sha256":"09d2db7b6e8636cce9af249d75ffaaf5f1fda7042725f46e43e8c3e9e012da4f","size":102930482,"kind":"archive"},{"filename":"go1.16.7.freebsd-amd64.tar.gz","os":"freebsd","arch":"amd64","version":"go1.16.7","sha256":"cf43ecac8a68c040354e8a45ba167ebc631091976ac370b6f1e444623bc77f37","size":129011611,"kind":"archive"},{"filename":"go1.16.7.linux-386.tar.gz","os":"linux","arch":"386","version":"go1.16.7","sha256":"5c0c8891fa88993f2193fbc9dd5cca6c250c89aa8c12bbaa382b6ff38139bcc3","size":103084876,"kind":"archive"},{"filename":"go1.16.7.linux-amd64.tar.gz","os":"linux","arch":"amd64","version":"go1.16.7","sha256":"7fe7a73f55ba3e2285da36f8b085e5c0159e9564ef5f63ee0ed6b818ade8ef04","size":129034961,"kind":"archive"},{"filename":"go1.16.7.linux-arm64.tar.gz","os":"linux","arch":"arm64","version":"go1.16.7","sha256":"63d6b53ecbd2b05c1f0e9903c92042663f2f68afdbb67f4d0d12700156869bac","size":99603989,"kind":"archive"},{"filename":"go1.16.7.linux-armv6l.tar.gz","os":"linux","arch":"armv6l","version":"go1.16.7","sha256":"b2973ceeae234866368baf9469fb7b9444857e50dc785ba879d98a0aa208a12b","size":100281970,"kind":"archive"},{"filename":"go1.16.7.linux-ppc64le.tar.gz","os":"linux","arch":"ppc64le","version":"go1.16.7","sha256":"03e02b2ac6dc1601203f335385b9bbe15a55677066d9a1a1280b5fcfa6ec4738","size":98094639,"kind":"archive"},{"filename":"go1.16.7.linux-s390x.tar.gz","os":"linux","arch":"s390x","version":"go1.16.7","sha256":"5f691c9551710ebb17bbda04389944aa7332f42ab28f92516a69fbd7860e7e9f","size":103222266,"kind":"archive"},{"filename":"go1.16.7.windows-386.zip","os":"windows","arch":"386","version":"go1.16.7","sha256":"53b32b48ee2797acf2c5fa8f83c0d42406ae6b5df7e3a57ccbe94cf6272faeec","size":117859438,"kind":"archive"},{"filename":"go1.16.7.windows-386.msi","os":"windows","arch":"386","version":"go1.16.7","sha256":"a8e4ed71d5bc393884f981928c4ca74e95130a6d032a7ba3e414e8e2ac2b5710","size":102830080,"kind":"installer"},{"filename":"go1.16.7.windows-amd64.zip","os":"windows","arch":"amd64","version":"go1.16.7","sha256":"56b3a9024268f226f679c3a8ffb21f4214a75f84050b2c395b362ae2cc8e53e9","size":143997221,"kind":"archive"},{"filename":"go1.16.7.windows-amd64.msi","os":"windows","arch":"amd64","version":"go1.16.7","sha256":"75597307c368ae1f728f9e7a2c2d5814225664b5b8d915d34c0d4eb2d53d0831","size":124407808,"kind":"installer"}]},{"version":"go1.15.15","stable":true,"files":[{"filename":"go1.15.15.src.tar.gz","os":"","arch":"","version":"go1.15.15","sha256":"0662ae3813330280d5f1a97a2ee23bbdbe3a5a7cfa6001b24a9873a19a0dc7ec","size":23042945,"kind":"source"},{"filename":"go1.15.15.darwin-amd64.tar.gz","os":"darwin","arch":"amd64","version":"go1.15.15","sha256":"2f4c119524450ee94062a1ce7112fb88ce0fe4bb0303a302e002183a550c25c2","size":122412248,"kind":"archive"},{"filename":"go1.15.15.darwin-amd64.pkg","os":"darwin","arch":"amd64","version":"go1.15.15","sha256":"f0e1877902ca88001cb768ae0dd8e974e58084ea6e64fb13f46289f842ef53ff
func TestVersions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(dlResp)
}))
dlURL = server.URL
versions, err := Versions(context.Background())
if err != nil {
t.Log(err)
t.FailNow()
}
if len(versions) != 2 {
t.Logf("Expected 2 versions but got %d\n", len(versions))
t.FailNow()
}
if !strings.EqualFold(versions[0].Version, "go1.16.7") {
t.Logf("Expected version go1.16.7 but got %s\n", versions[0].Version)
t.FailNow()
}
}