Skip to content

Commit

Permalink
add invalid dmitri.shuralyov.com/test/modtest2 test module
Browse files Browse the repository at this point in the history
This change adds a test module that is served over a module proxy
URL with an empty host (i.e., "https://"). It exists only for testing
purposes, since such module proxy URLs are not valid as of Go 1.13,
and all normal modules are being served with a module proxy URL that
has non-empty host as of commit 17791dc.

Updates #24
Updates golang/go#32006
  • Loading branch information
dmitshur committed Nov 17, 2019
1 parent afe2cda commit 021485b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"archive/zip"
"io"
"net/http"
)
Expand All @@ -26,4 +27,49 @@ func init() {
http.HandleFunc("/test/modtest1/inner", h)
http.HandleFunc("/test/modtest1/inner/p", h)
}

// For testing Go module proxy URLs with an empty host. Such module proxy URLs unintentionally
// worked without error in Go 1.11 and 1.12. Go 1.13 has fixed it, so they no longer do.
// See https://golang.org/issue/32006#issuecomment-491943083.
{
http.HandleFunc("/test/modtest2", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
io.WriteString(w, `<meta name="go-import" content="dmitri.shuralyov.com/test/modtest2 mod https://">`)
})
http.HandleFunc("/test/modtest2/@v/list", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
io.WriteString(w, "v0.0.0\n")
})
http.HandleFunc("/test/modtest2/@v/v0.0.0.info", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
io.WriteString(w, "{\n\t\"Version\": \"v0.0.0\",\n\t\"Time\": \"2019-05-04T15:44:36Z\"\n}\n")
})
http.HandleFunc("/test/modtest2/@v/v0.0.0.mod", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
io.WriteString(w, "module dmitri.shuralyov.com/test/modtest2\n")
})
http.HandleFunc("/test/modtest2/@v/v0.0.0.zip", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/zip")
z := zip.NewWriter(w)
for _, file := range []struct {
Name, Body string
}{
{"dmitri.shuralyov.com/test/modtest2@v0.0.0/go.mod", "module dmitri.shuralyov.com/test/modtest2\n"},
{"dmitri.shuralyov.com/test/modtest2@v0.0.0/p.go", "package p\n\n// Life is the answer.\nconst Life = 42\n"},
} {
f, err := z.Create(file.Name)
if err != nil {
panic(err)
}
_, err = f.Write([]byte(file.Body))
if err != nil {
panic(err)
}
}
err := z.Close()
if err != nil {
panic(err)
}
})
}
}

0 comments on commit 021485b

Please sign in to comment.