2016-12-17 03:45:16 +03:00
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-01-27 23:39:07 +03:00
|
|
|
package dep
|
2016-12-17 03:45:16 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2017-02-02 05:18:35 +03:00
|
|
|
|
2017-05-10 07:24:12 +03:00
|
|
|
"github.com/golang/dep/internal/test"
|
2016-12-17 03:45:16 +03:00
|
|
|
)
|
|
|
|
|
2017-02-20 01:36:16 +03:00
|
|
|
func TestAnalyzerDeriveManifestAndLock(t *testing.T) {
|
2017-02-02 05:18:35 +03:00
|
|
|
h := test.NewHelper(t)
|
|
|
|
defer h.Cleanup()
|
2016-12-17 03:45:16 +03:00
|
|
|
|
2017-02-02 05:18:35 +03:00
|
|
|
h.TempDir("dep")
|
2017-04-02 22:36:22 +03:00
|
|
|
golden := filepath.Join("analyzer", ManifestName)
|
2017-02-10 21:08:47 +03:00
|
|
|
want := h.GetTestFileString(golden)
|
2017-02-09 05:37:31 +03:00
|
|
|
h.TempCopy(filepath.Join("dep", ManifestName), golden)
|
2016-12-17 03:45:16 +03:00
|
|
|
|
2017-04-15 08:23:16 +03:00
|
|
|
a := Analyzer{}
|
2016-12-17 03:45:16 +03:00
|
|
|
|
2017-02-02 05:18:35 +03:00
|
|
|
m, l, err := a.DeriveManifestAndLock(h.Path("dep"), "my/fake/project")
|
2016-12-17 03:45:16 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-03-20 21:14:02 +03:00
|
|
|
got, err := m.(*Manifest).MarshalTOML()
|
2016-12-17 03:45:16 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-02-10 21:08:47 +03:00
|
|
|
if want != string(got) {
|
2017-02-09 05:37:31 +03:00
|
|
|
if *test.UpdateGolden {
|
2017-02-10 21:08:47 +03:00
|
|
|
if err := h.WriteTestFile(golden, string(got)); err != nil {
|
2017-02-09 05:37:31 +03:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
} else {
|
2017-09-29 11:49:51 +03:00
|
|
|
t.Fatalf("(WNT):\n%s\n(GOT):\n%s", want, string(got))
|
2017-02-09 05:37:31 +03:00
|
|
|
}
|
2016-12-17 03:45:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if l != nil {
|
|
|
|
t.Fatalf("expected lock to be nil, got: %#v", l)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-20 01:36:16 +03:00
|
|
|
func TestAnalyzerDeriveManifestAndLockDoesNotExist(t *testing.T) {
|
|
|
|
h := test.NewHelper(t)
|
|
|
|
defer h.Cleanup()
|
|
|
|
|
|
|
|
h.TempDir("dep")
|
|
|
|
|
|
|
|
a := Analyzer{}
|
|
|
|
|
|
|
|
m, l, err := a.DeriveManifestAndLock(h.Path("dep"), "my/fake/project")
|
|
|
|
if m != nil || l != nil || err != nil {
|
|
|
|
t.Fatalf("expected manifest & lock & err to be nil: m -> %#v l -> %#v err-> %#v", m, l, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnalyzerDeriveManifestAndLockCannotOpen(t *testing.T) {
|
|
|
|
h := test.NewHelper(t)
|
|
|
|
defer h.Cleanup()
|
|
|
|
|
|
|
|
h.TempDir("dep")
|
|
|
|
|
2017-05-02 09:22:44 +03:00
|
|
|
// Simulate an inaccessible manifest file.
|
2017-02-20 01:36:16 +03:00
|
|
|
h.TempFile(filepath.Join("dep", ManifestName), "")
|
2017-05-02 09:22:44 +03:00
|
|
|
closer, err := makeUnreadable(filepath.Join(h.Path("dep"), ManifestName))
|
2016-12-17 03:45:16 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-05-02 09:22:44 +03:00
|
|
|
defer closer.Close()
|
2016-12-17 03:45:16 +03:00
|
|
|
|
2017-04-15 08:23:16 +03:00
|
|
|
a := Analyzer{}
|
2016-12-17 03:45:16 +03:00
|
|
|
|
2017-05-02 09:22:44 +03:00
|
|
|
// Verify that the solver rejects the manifest, rather than treating it as
|
|
|
|
// offering no constraints.
|
2017-02-20 01:36:16 +03:00
|
|
|
m, l, err := a.DeriveManifestAndLock(h.Path("dep"), "my/fake/project")
|
|
|
|
if m != nil || l != nil || err == nil {
|
|
|
|
t.Fatalf("expected manifest & lock to be nil, err to be not nil: m -> %#v l -> %#v err -> %#v", m, l, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnalyzerDeriveManifestAndLockInvalidManifest(t *testing.T) {
|
|
|
|
h := test.NewHelper(t)
|
|
|
|
defer h.Cleanup()
|
|
|
|
|
|
|
|
h.TempDir("dep")
|
|
|
|
|
|
|
|
// Create a manifest with invalid contents
|
|
|
|
h.TempFile(filepath.Join("dep", ManifestName), "invalid manifest")
|
|
|
|
|
|
|
|
a := Analyzer{}
|
|
|
|
|
|
|
|
m, l, err := a.DeriveManifestAndLock(h.Path("dep"), "my/fake/project")
|
|
|
|
if m != nil || l != nil || err == nil {
|
2016-12-17 03:45:16 +03:00
|
|
|
t.Fatalf("expected manifest & lock & err to be nil: m -> %#v l -> %#v err-> %#v", m, l, err)
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 01:36:16 +03:00
|
|
|
|
|
|
|
func TestAnalyzerInfo(t *testing.T) {
|
|
|
|
a := Analyzer{}
|
|
|
|
|
2017-06-14 19:56:28 +03:00
|
|
|
info := a.Info()
|
2017-02-20 01:36:16 +03:00
|
|
|
|
2017-06-14 19:56:28 +03:00
|
|
|
if info.Name != "dep" || info.Version != 1 {
|
|
|
|
t.Fatalf("expected name to be 'dep' and version to be 1: name -> %q vers -> %d", info.Name, info.Version)
|
2017-02-20 01:36:16 +03:00
|
|
|
}
|
|
|
|
}
|