diff --git a/cmd/dep/godep_config.go b/cmd/dep/godep_config.go index bb657dee9c..9691c95c11 100644 --- a/cmd/dep/godep_config.go +++ b/cmd/dep/godep_config.go @@ -11,7 +11,7 @@ import ( ) type godepFile struct { - json godepJSON + json godepJson loggers *dep.Loggers } @@ -19,7 +19,7 @@ func newGodepFile(loggers *dep.Loggers) *godepFile { return &godepFile{loggers: loggers} } -type godepJSON struct { +type godepJson struct { Name string `json:"ImportPath"` Imports []godepPackage `json:"Deps"` } @@ -32,7 +32,7 @@ type godepPackage struct { // load parses Godeps.json in projectDir and unmarshals the json to godepFile.json func (g *godepFile) load(projectDir string) error { - j := filepath.Join(projectDir, godepJSONpath) + j := filepath.Join(projectDir, "Godeps", godepJsonName) if g.loggers.Verbose { g.loggers.Err.Printf("godep: Loading %s", j) } diff --git a/cmd/dep/godep_config_test.go b/cmd/dep/godep_config_test.go index 5f56a43884..9843f9c151 100644 --- a/cmd/dep/godep_config_test.go +++ b/cmd/dep/godep_config_test.go @@ -12,9 +12,9 @@ import ( const testGodepProjectRoot = "github.com/golang/notexist" -func TestGodepJSONLoad(t *testing.T) { +func TestGodepJsonLoad(t *testing.T) { // This is same as cmd/dep/testdata/Godeps.json - wantJSON := godepJSON{ + wantJSON := godepJson{ Name: "github.com/golang/notexist", Imports: []godepPackage{ { @@ -32,7 +32,7 @@ func TestGodepJSONLoad(t *testing.T) { h := test.NewHelper(t) defer h.Cleanup() - h.TempCopy(filepath.Join(testGodepProjectRoot, godepJSONpath), "Godeps.json") + h.TempCopy(filepath.Join(testGodepProjectRoot, "Godeps", godepJsonName), "Godeps.json") projectRoot := h.Path(testGodepProjectRoot) @@ -66,7 +66,7 @@ func TestGodepConvertProject(t *testing.T) { f := godepFile{ loggers: loggers, - json: godepJSON{ + json: godepJson{ Name: "github.com/foo/bar", Imports: []godepPackage{ { @@ -113,7 +113,7 @@ func TestGodepConvertBadInput_EmptyPackageName(t *testing.T) { f := godepFile{ loggers: loggers, - json: godepJSON{ + json: godepJson{ Imports: []godepPackage{{ImportPath: ""}}, }, } diff --git a/cmd/dep/godep_importer.go b/cmd/dep/godep_importer.go index 718aafb98e..b651e84422 100644 --- a/cmd/dep/godep_importer.go +++ b/cmd/dep/godep_importer.go @@ -8,8 +8,7 @@ import ( "github.com/golang/dep/internal/gps" ) -// Godeps/Godeps.json -const godepJSONpath = "Godeps/Godeps.json" +const godepJsonName = "Godeps.json" type godepImporter struct { loggers *dep.Loggers @@ -21,7 +20,7 @@ func newGodepImporter(loggers *dep.Loggers, sm gps.SourceManager) *godepImporter } func (i godepImporter) HasConfig(dir string) bool { - y := filepath.Join(dir, godepJSONpath) + y := filepath.Join(dir, "Godeps", godepJsonName) if _, err := os.Stat(y); err != nil { return false } @@ -30,11 +29,11 @@ func (i godepImporter) HasConfig(dir string) bool { } func (i godepImporter) Import(dir string, pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) { - files := newGlideFiles(i.loggers) - err := files.load(dir) + file := newGodepFile(i.loggers) + err := file.load(dir) if err != nil { return nil, nil, err } - return files.convert(string(pr), i.sm) + return file.convert(string(pr), i.sm) } diff --git a/cmd/dep/godep_importer_test.go b/cmd/dep/godep_importer_test.go new file mode 100644 index 0000000000..f26d3b2172 --- /dev/null +++ b/cmd/dep/godep_importer_test.go @@ -0,0 +1,48 @@ +package main + +import ( + "log" + "os" + "path/filepath" + "testing" + + "github.com/golang/dep" + "github.com/golang/dep/internal/gps" + "github.com/golang/dep/internal/test" +) + +func TestGodepImport(t *testing.T) { + h := test.NewHelper(t) + defer h.Cleanup() + + cacheDir := "gps-repocache" + h.TempDir(cacheDir) + h.TempDir("src") + h.TempDir(filepath.Join("src", testGlideProjectRoot)) + h.TempCopy(filepath.Join(testGodepProjectRoot, "Godeps", godepJsonName), "Godeps.json") + + loggers := &dep.Loggers{ + Out: log.New(os.Stdout, "", 0), + Err: log.New(os.Stderr, "", 0), + Verbose: true, + } + projectRoot := h.Path(testGodepProjectRoot) + sm, err := gps.NewSourceManager(h.Path(cacheDir)) + h.Must(err) + + i := newGodepImporter(loggers, sm) + if !i.HasConfig(projectRoot) { + t.Fatal("Expected the importer to detect the godep configuration file") + } + + m, l, err := i.Import(projectRoot, gps.ProjectRoot(testGodepProjectRoot)) + h.Must(err) + + if m == nil { + t.Fatal("Expected the manifest to be generated") + } + + if l == nil { + t.Fatal("Expected the lock to be generated") + } +}