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

Commit de4c20a

Browse files
Ray Tungjessfraz
Ray Tung
authored andcommitted
Added more tests to main_test.go
Increased main.go coverage from 12.8% to 21.8% - Added test for `project.makeParams()` - Added an extra test for `findProjectRoot()`
1 parent e9d6340 commit de4c20a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

main_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
package main
66

77
import (
8+
"fmt"
89
"os"
910
"path/filepath"
1011
"runtime"
1112
"testing"
13+
14+
"github.com/sdboyer/gps"
1215
)
1316

1417
func TestFindRoot(t *testing.T) {
@@ -40,6 +43,20 @@ func TestFindRoot(t *testing.T) {
4043
t.Errorf("findProjectRoot on nonexistent subdir should still work and give %s, got %s", expect, got3)
4144
}
4245

46+
root := "/"
47+
returnedPath, projectRootErr := findProjectRoot(root)
48+
if returnedPath != "" {
49+
t.Errorf("findProjectRoot with path %s returned non empty string: %s", root, returnedPath)
50+
}
51+
if projectRootErr == nil {
52+
t.Errorf("findProjectRoot with path %s should return error", root)
53+
}
54+
errStr := fmt.Sprintf("%v", projectRootErr.Error())
55+
expectedStr := "could not find project manifest.json, use dep init to initiate a manifest"
56+
if errStr != expectedStr {
57+
t.Errorf("Incorrect errProjectNotFound error. Found: %s. Expected: %s", errStr, expectedStr)
58+
}
59+
4360
// the following test does not work on windows because syscall.Stat does not
4461
// return a "not a directory" error
4562
if runtime.GOOS != "windows" {
@@ -49,3 +66,22 @@ func TestFindRoot(t *testing.T) {
4966
}
5067
}
5168
}
69+
70+
func TestProjectMakeParams(t *testing.T) {
71+
p := project{
72+
absroot: "someroot",
73+
importroot: gps.ProjectRoot("Some project root"),
74+
m: &manifest{Ignores: []string{"ignoring this"}},
75+
l: &lock{},
76+
}
77+
78+
solveParam := p.makeParams()
79+
80+
if solveParam.Manifest != p.m {
81+
t.Error("makeParams() returned gps.SolveParameters with incorrect Manifest")
82+
}
83+
84+
if solveParam.Lock != p.l {
85+
t.Error("makeParams() returned gps.SolveParameters with incorrect Lock")
86+
}
87+
}

0 commit comments

Comments
 (0)