Get new config test working
diff --git a/cfg/config_test.go b/cfg/config_test.go
index 082a9a4..58e0904 100644
--- a/cfg/config_test.go
+++ b/cfg/config_test.go
@@ -1,35 +1,14 @@
package cfg
import (
+ "reflect"
"testing"
+ "github.com/sdboyer/gps"
+
"gopkg.in/yaml.v2"
)
-var yml = `
-package: fake/testing
-description: foo bar baz
-homepage: https://example.com
-license: MIT
-owners:
-- name: foo
- email: bar@example.com
- homepage: https://example.com
-dependencies:
-- github.com/kylelemons/go-gypsy:
- version: 1.0.0
-- github.com/Masterminds/convert:
- repo: git@github.com:Masterminds/convert.git
- version: a9949121a2e2192ca92fa6dddfeaaa4a4412d955
-- github.com/Masterminds/structable:
- branch: master
-- github.com/Masterminds/cookoo/convert
- repo: https://github.com/cookoo/convert.git
-
-testDependencies:
- - package: github.com/kylelemons/go-gypsy
-`
-
var lyml = `
package: fake/testing
description: foo bar baz
@@ -65,9 +44,133 @@
- package: github.com/kylelemons/go-gypsy
`
+var yml = `
+package: fake/testing
+description: foo bar baz
+homepage: https://example.com
+license: MIT
+owners:
+- name: foo
+ email: bar@example.com
+ homepage: https://example.com
+dependencies:
+ - package: github.com/kylelemons/go-gypsy
+ version: v1.0.0
+ - package: github.com/Masterminds/convert
+ repo: git@github.com:Masterminds/convert.git
+ version: a9949121a2e2192ca92fa6dddfeaaa4a4412d955
+ - package: github.com/Masterminds/structable
+ branch: master
+ - package: github.com/Masterminds/cookoo
+ repo: git://github.com/Masterminds/cookoo
+ - package: github.com/sdboyer/gps
+ version: ^v1.0.0
+
+testDependencies:
+ - package: github.com/Sirupsen/logrus
+ version: ~v1.0.0
+`
+
+func TestManualConfigFromYaml(t *testing.T) {
+ cfg := &Config{}
+ err := yaml.Unmarshal([]byte(yml), &cfg)
+ if err != nil {
+ t.Errorf("Unable to Unmarshal config yaml")
+ }
+
+ found := make(map[string]bool)
+ for _, i := range cfg.Imports {
+ found[i.Name] = true
+
+ switch i.Name {
+ case "github.com/kylelemons/go-gypsy":
+ ref := gps.NewVersion("v1.0.0")
+ if i.Constraint != ref {
+ t.Errorf("(%s) Expected %q for constraint, got %q", i.Name, ref, i.Constraint)
+ }
+
+ case "github.com/Masterminds/convert":
+ ref := gps.Revision("a9949121a2e2192ca92fa6dddfeaaa4a4412d955")
+ if i.Constraint != ref {
+ t.Errorf("(%s) Expected %q for constraint, got %q", i.Name, ref, i.Constraint)
+ }
+
+ repo := "git@github.com:Masterminds/convert.git"
+ if i.Repository != repo {
+ t.Errorf("(%s) Expected %q for repository, got %q", i.Name, repo, i.Repository)
+ }
+
+ case "github.com/Masterminds/structable":
+ ref := gps.NewBranch("master")
+ if i.Constraint != ref {
+ t.Errorf("(%s) Expected %q for constraint, got %q", i.Name, ref, i.Constraint)
+ }
+
+ case "github.com/Masterminds/cookoo":
+ repo := "git://github.com/Masterminds/cookoo"
+ if i.Repository != repo {
+ t.Errorf("(%s) Expected %q for repository, got %q", i.Name, repo, i.Repository)
+ }
+
+ case "github.com/sdboyer/gps":
+ sv, _ := gps.NewSemverConstraint("^v1.0.0")
+ if !reflect.DeepEqual(sv, i.Constraint) {
+ t.Errorf("(%s) Expected %q for constraint, got %q", i.Name, sv, i.Constraint)
+ }
+ }
+ }
+
+ names := []string{
+ "github.com/Masterminds/convert",
+ "github.com/Masterminds/cookoo",
+ "github.com/Masterminds/structable",
+ "github.com/kylelemons/go-gypsy",
+ "github.com/sdboyer/gps",
+ }
+
+ for _, n := range names {
+ if !found[n] {
+ t.Errorf("Could not find config entry for %s", n)
+
+ }
+ }
+
+ if len(cfg.DevImports) != 1 {
+ t.Errorf("Expected 1 entry in DevImports, got %v", len(cfg.DevImports))
+ } else {
+ ti := cfg.DevImports[0]
+ n := "github.com/Sirupsen/logrus"
+ if ti.Name != n {
+ t.Errorf("Expected test dependency to be %s, got %s", n, ti.Name)
+ }
+
+ sv, _ := gps.NewSemverConstraint("~v1.0.0")
+ if !reflect.DeepEqual(sv, ti.Constraint) {
+ t.Errorf("(test dep: %s) Expected %q for constraint, got %q", ti.Name, sv, ti.Constraint)
+ }
+ }
+
+ if cfg.Name != "fake/testing" {
+ t.Errorf("Inaccurate name found %s", cfg.Name)
+ }
+
+ if cfg.Description != "foo bar baz" {
+ t.Errorf("Inaccurate description found %s", cfg.Description)
+ }
+
+ if cfg.Home != "https://example.com" {
+ t.Errorf("Inaccurate homepage found %s", cfg.Home)
+ }
+
+ if cfg.License != "MIT" {
+ t.Errorf("Inaccurate license found %s", cfg.License)
+ }
+
+}
+
func TestLegacyManualConfigFromYaml(t *testing.T) {
cfg := &lConfig1{}
- err := yaml.Unmarshal([]byte(yml), &cfg)
+ err := yaml.Unmarshal([]byte(lyml), &cfg)
if err != nil {
t.Errorf("Unable to Unmarshal config yaml")
}
@@ -136,7 +239,7 @@
}
func TestConfigFromYaml(t *testing.T) {
- c, legacy, err := ConfigFromYaml([]byte(yml))
+ c, _, err := ConfigFromYaml([]byte(yml))
if err != nil {
t.Error("ConfigFromYaml failed to parse yaml")
}
@@ -147,7 +250,7 @@
}
func TestHasDependency(t *testing.T) {
- c, legacy, err := ConfigFromYaml([]byte(yml))
+ c, _, err := ConfigFromYaml([]byte(yml))
if err != nil {
t.Error("ConfigFromYaml failed to parse yaml for HasDependency")
}
diff --git a/glide.lock b/glide.lock
index 9a968e2..a5d5c91 100644
--- a/glide.lock
+++ b/glide.lock
@@ -10,7 +10,7 @@
- name: github.com/Masterminds/vcs
version: fbe9fb6ad5b5f35b3e82a7c21123cfc526cbf895
- name: github.com/sdboyer/gps
- version: 278a227dfc3d595a33a77ff3f841fd8ca1bc8cd0
+ version: f6e74e8d79b34ee6954d0cc8b770758ec99870ad
- name: github.com/termie/go-shutil
version: bcacb06fecaeec8dc42af03c87c6949f4a05c74c
- name: gopkg.in/yaml.v2
diff --git a/vendor/github.com/sdboyer/gps/constraints.go b/vendor/github.com/sdboyer/gps/constraints.go
index affde86..794100e 100644
--- a/vendor/github.com/sdboyer/gps/constraints.go
+++ b/vendor/github.com/sdboyer/gps/constraints.go
@@ -46,6 +46,11 @@
if err != nil {
return nil, err
}
+ // If we got a simple semver.Version, simplify by returning our
+ // corresponding type
+ if sv, ok := c.(*semver.Version); ok {
+ return semVersion{sv: sv}, nil
+ }
return semverConstraint{c: c}, nil
}