Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
add tests for importer failure scenarios
Browse files Browse the repository at this point in the history
- internal/importers/base/importer_test.go:
  - Check for warning when an invalid project is present whose project root
    cannot be parsed.
  - Check for warning when lock hint cannot be resolved correctly and the
    constraint cannot be applied.
- Integration test for malformed external config(glide.yaml)
  • Loading branch information
sudo-suhas committed Dec 27, 2017
1 parent 80f9306 commit 5f45022
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/dep/testdata/harness_tests/init/glide/case4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore glide config if glide.yaml is malformed and cannot be parsed correctly.
21 changes: 21 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide/case4/final/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[[constraint]]
name = "github.com/sdboyer/deptestdos"
version = "2.0.0"
20 changes: 20 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide/case4/initial/glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'package: github.com/golang/notexist
homepage: http://example.com
license: MIT
owners:
- name: Sam Boyer
email: [email protected]
homepage: http://sdboyer.io
ignore:
- github.com/sdboyer/dep-test
excludeDirs:
- samples
import:
- package: github.com/sdboyer/deptest # This is a transitive dep and will be ignored
repo: https://github.com/sdboyer/deptest.git
vcs: git
version: v1.0.0
- package: github.com/sdboyer/deptestdos
version: v2.0.0
testImport:
- package: github.com/golang/lint
16 changes: 16 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide/case4/initial/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017 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.

package main

import (
"fmt"

"github.com/sdboyer/deptestdos"
)

func main() {
var x deptestdos.Bar
fmt.Println(x)
}
14 changes: 14 additions & 0 deletions cmd/dep/testdata/harness_tests/init/glide/case4/testcase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"commands": [
["init", "-no-examples"]
],
"error-expected": "",
"gopath-initial": {
"github.com/sdboyer/deptest": "3f4c3bea144e112a69bbe5d8d01c1b09a544253f",
"github.com/sdboyer/deptestdos": "5c607206be5decd28e6263ffffdcee067266015e"
},
"vendor-final": [
"github.com/sdboyer/deptest",
"github.com/sdboyer/deptestdos"
]
}
27 changes: 27 additions & 0 deletions internal/importers/base/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package base

import (
"fmt"
"log"
"testing"

Expand Down Expand Up @@ -399,6 +400,32 @@ func TestBaseImporter_ImportProjects(t *testing.T) {
},
},
},
"invalid project root": {
importertest.TestCase{
WantSourceRepo: "",
WantWarning: "Warning: Skipping project. Cannot determine the project root for invalid-project",
},
[]ImportedPackage{
{
Name: "invalid-project",
},
},
},
"nonexistent project": {
importertest.TestCase{
WantSourceRepo: "",
WantWarning: fmt.Sprintf(
"Warning: Unable to apply constraint %q for %s",
importertest.V1Tag, importertest.NonexistentPrj,
),
},
[]ImportedPackage{
{
Name: importertest.NonexistentPrj,
LockHint: importertest.V1Tag,
},
},
},
}

for name, tc := range testcases {
Expand Down
3 changes: 3 additions & 0 deletions internal/importers/importertest/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ const (

// MultiTaggedPlainTag is a non-semver tag on MultiTaggedRev.
MultiTaggedPlainTag = "stable"

// NonexistentPrj is a dummy project which does not exist on Github.
NonexistentPrj = "github.com/nonexistent/project"
)

0 comments on commit 5f45022

Please sign in to comment.