github.com/sirkon/goproxy@v1.4.8/internal/modload/import_test.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package modload 6 7 import ( 8 "github.com/sirkon/goproxy/internal/testenv" 9 "regexp" 10 "strings" 11 "testing" 12 ) 13 14 var importTests = []struct { 15 path string 16 err string 17 }{ 18 { 19 path: "golang.org/x/net/context", 20 err: "missing module for import: golang.org/x/net@.* provides golang.org/x/net/context", 21 }, 22 { 23 path: "golang.org/x/net", 24 err: "cannot find module providing package golang.org/x/net", 25 }, 26 { 27 path: "golang.org/x/text", 28 err: "missing module for import: golang.org/x/text@.* provides golang.org/x/text", 29 }, 30 { 31 path: "github.com/rsc/quote/buggy", 32 err: "missing module for import: github.com/rsc/quote@v1.5.2 provides github.com/rsc/quote/buggy", 33 }, 34 { 35 path: "github.com/rsc/quote", 36 err: "missing module for import: github.com/rsc/quote@v1.5.2 provides github.com/rsc/quote", 37 }, 38 { 39 path: "golang.org/x/foo/bar", 40 err: "cannot find module providing package golang.org/x/foo/bar", 41 }, 42 } 43 44 func TestImport(t *testing.T) { 45 testenv.MustHaveExternalNetwork(t) 46 47 for _, tt := range importTests { 48 t.Run(strings.Replace(tt.path, "/", "_", -1), func(t *testing.T) { 49 // Note that there is no build list, so Import should always fail. 50 m, dir, err := Import(tt.path) 51 if err == nil { 52 t.Fatalf("Import(%q) = %v, %v, nil; expected error", tt.path, m, dir) 53 } 54 if !regexp.MustCompile(tt.err).MatchString(err.Error()) { 55 t.Fatalf("Import(%q): error %q, want error matching %#q", tt.path, err, tt.err) 56 } 57 }) 58 } 59 }