35 lines
7.0 KiB
Go
35 lines
7.0 KiB
Go
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","size":122786419,"kind":"installer"},{"filename":"go1.15.15.freebsd-386.tar.gz","os":"freebsd","arch":"386","version":"go1.15.15","sha256":"7174078a53e330cf351dc20bed6682033f44066d8aed754139bcaef52e53c214","size":100310476,"kind":"archive"},{"filename":"go1.15.15.freebsd-amd64.tar.gz","os":"freebsd","arch":"amd64","version":"go1.15.15","sha256":"1f80a20419b2618182ef5b9615dd990b32b952d81b354b373c6fd304527bb70c","size":121000844,"kind":"archive"},{"filename":"go1.15.15.linux-386.tar.gz","os":"linux","arch":"386","version":"go1.15.15","sha256":"3310fb0e48b0907bb520f6e3c6dcff63cc0913b92a76456f12980d0eb13b77d4","size":100580037,"kind":"archive"},{"filename":"go1.15.15.linux-amd64.tar.gz","os":"linux","arch":"amd64","version":"go1.15.15","sha256":"0885cf046a9f099e260d98d9ec5d19ea9328f34c8dc4956e1d3cd87daaddb345","size":121104410,"kind":"archive"},{"filename":"go1.15.15.linux-arm64.tar.gz","os":"linux","arch":"arm64","version":"go1.15.15","sha256":"714abb01af210473dd6af331094ad6847162eff81a7fc7241d24f5a85496c9fa","size":97717057,"kind":"archive"},{"filename":"go1.15.15.linux-armv6l.tar.gz","os":"linux","arch":"armv6l","version":"go1.15.15","sha256":"7192603af50afb23c9d8cd14d2b2c19e0985a34d3eca685fa098df7893000d19","size":97989611,"kind":"archive"},{"filename":"go1.15.15.linux-ppc64le.tar.gz","os":"linux","arch":"ppc64le","version":"go1.15.15","sha256":"37f3b99e21d0324a6583159e14e42e57e56561abbf7bf68bef3d8f57b29e39c0","size":96442143,"kind":"archive"},{"filename":"go1.15.15.linux-s390x.tar.gz","os":"linux","arch":"s390x","version":"go1.15.15","sha256":"eae39d97df6b758636d5427be0b083dbf9d49007b302825ac6c8645de039aaab","size":101198583,"kind":"archive"},{"filename":"go1.15.15.windows-386.zip","os":"windows","arch":"386","version":"go1.15.15","sha256":"4036abdeb36c7db380d05f3ffd087b754c34df06b202ee381da77f4c5a44aa58","size":118256667,"kind":"archive"},{"filename":"go1.15.15.windows-386.msi","os":"windows","arch":"386","version":"go1.15.15","sha256":"04d406e45da74f67151ca9b720899d18a8707d77e83f07ba11f9b099ced3fff1","size":103342080,"kind":"installer"},{"filename":"go1.15.15.windows-amd64.zip","os":"windows","arch":"amd64","version":"go1.15.15","sha256":"7df7bf948dcc8ec0a3902e3301d17cbb5c2ebb01297d686ee2302e41f4ac6e10","size":139064376,"kind":"archive"},{"filename":"go1.15.15.windows-amd64.msi","os":"windows","arch":"amd64","version":"go1.15.15","sha256":"c76656a253cc4c7a0ba7ae006cadc0bf2d6df7066acb8df84460eac94dc3a7d1","size":120983552,"kind":"installer"}]}]`)
|
|
|
|
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()
|
|
}
|
|
}
|