|
5 | 5 | package dep
|
6 | 6 |
|
7 | 7 | import (
|
8 |
| - "io/ioutil" |
9 | 8 | "os"
|
10 | 9 | "path/filepath"
|
| 10 | + "runtime" |
11 | 11 | "testing"
|
12 | 12 |
|
13 | 13 | "github.com/golang/dep/test"
|
14 | 14 | )
|
15 | 15 |
|
16 |
| -func TestDeriveManifestAndLock(t *testing.T) { |
| 16 | +func TestAnalyzerDeriveManifestAndLock(t *testing.T) { |
17 | 17 | h := test.NewHelper(t)
|
18 | 18 | defer h.Cleanup()
|
19 | 19 |
|
@@ -49,17 +49,75 @@ func TestDeriveManifestAndLock(t *testing.T) {
|
49 | 49 | }
|
50 | 50 | }
|
51 | 51 |
|
52 |
| -func TestDeriveManifestAndLockDoesNotExist(t *testing.T) { |
53 |
| - dir, err := ioutil.TempDir("", "dep") |
| 52 | +func TestAnalyzerDeriveManifestAndLockDoesNotExist(t *testing.T) { |
| 53 | + h := test.NewHelper(t) |
| 54 | + defer h.Cleanup() |
| 55 | + |
| 56 | + h.TempDir("dep") |
| 57 | + |
| 58 | + a := Analyzer{} |
| 59 | + |
| 60 | + m, l, err := a.DeriveManifestAndLock(h.Path("dep"), "my/fake/project") |
| 61 | + if m != nil || l != nil || err != nil { |
| 62 | + t.Fatalf("expected manifest & lock & err to be nil: m -> %#v l -> %#v err-> %#v", m, l, err) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func TestAnalyzerDeriveManifestAndLockCannotOpen(t *testing.T) { |
| 67 | + if runtime.GOOS == "windows" { |
| 68 | + // TODO: find an implementation that works on Microsoft |
| 69 | + // Windows. Setting permissions works differently there. |
| 70 | + // os.Chmod(..., 0222) below is not enough for the file |
| 71 | + // to be write-only (unreadable), and os.Chmod(..., |
| 72 | + // 0000) returns an invalid argument error. |
| 73 | + t.Skip("skipping on windows") |
| 74 | + } |
| 75 | + |
| 76 | + h := test.NewHelper(t) |
| 77 | + defer h.Cleanup() |
| 78 | + |
| 79 | + h.TempDir("dep") |
| 80 | + |
| 81 | + // Create an empty manifest file |
| 82 | + h.TempFile(filepath.Join("dep", ManifestName), "") |
| 83 | + |
| 84 | + // Change its mode so that it cannot be read |
| 85 | + err := os.Chmod(filepath.Join(h.Path("dep"), ManifestName), 0222) |
54 | 86 | if err != nil {
|
55 | 87 | t.Fatal(err)
|
56 | 88 | }
|
57 |
| - defer os.RemoveAll(dir) |
58 | 89 |
|
59 | 90 | a := Analyzer{}
|
60 | 91 |
|
61 |
| - m, l, err := a.DeriveManifestAndLock(dir, "my/fake/project") |
62 |
| - if m != nil || l != nil || err != nil { |
| 92 | + m, l, err := a.DeriveManifestAndLock(h.Path("dep"), "my/fake/project") |
| 93 | + if m != nil || l != nil || err == nil { |
| 94 | + t.Fatalf("expected manifest & lock to be nil, err to be not nil: m -> %#v l -> %#v err -> %#v", m, l, err) |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +func TestAnalyzerDeriveManifestAndLockInvalidManifest(t *testing.T) { |
| 99 | + h := test.NewHelper(t) |
| 100 | + defer h.Cleanup() |
| 101 | + |
| 102 | + h.TempDir("dep") |
| 103 | + |
| 104 | + // Create a manifest with invalid contents |
| 105 | + h.TempFile(filepath.Join("dep", ManifestName), "invalid manifest") |
| 106 | + |
| 107 | + a := Analyzer{} |
| 108 | + |
| 109 | + m, l, err := a.DeriveManifestAndLock(h.Path("dep"), "my/fake/project") |
| 110 | + if m != nil || l != nil || err == nil { |
63 | 111 | t.Fatalf("expected manifest & lock & err to be nil: m -> %#v l -> %#v err-> %#v", m, l, err)
|
64 | 112 | }
|
65 | 113 | }
|
| 114 | + |
| 115 | +func TestAnalyzerInfo(t *testing.T) { |
| 116 | + a := Analyzer{} |
| 117 | + |
| 118 | + name, vers := a.Info() |
| 119 | + |
| 120 | + if name != "dep" || vers != 1 { |
| 121 | + t.Fatalf("expected name to be 'dep' and version to be 1: name -> %q vers -> %d", name, vers) |
| 122 | + } |
| 123 | +} |
0 commit comments