Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1159)

Unified Diff: vpython/spec/match_test.go

Issue 2921133002: [vpython] Add conditional packages based on PEP425 (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: vpython/spec/match_test.go
diff --git a/vpython/spec/match_test.go b/vpython/spec/match_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..23cf3293548de85573ada000b4652cfc65b752bb
--- /dev/null
+++ b/vpython/spec/match_test.go
@@ -0,0 +1,160 @@
+// Copyright 2017 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package spec
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ "github.com/luci/luci-go/vpython/api/vpython"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func mkTag(version, abi, arch string) *vpython.Pep425Tag {
+ return &vpython.Pep425Tag{
+ Version: version,
+ Abi: abi,
+ Arch: arch,
qyearsley 2017/06/05 20:20:08 Note, I guess Pep425Tag is defined elsewhere(?) bu
dnj 2017/06/06 13:59:10 Yeah, unfortunately fixing these field names would
dnj 2017/06/06 14:29:34 FYI, filed this to fix naming: https://codereview.
+ }
+}
+
+func tagString(tags []*vpython.Pep425Tag) string {
+ parts := make([]string, len(tags))
+ for i, tag := range tags {
+ parts[i] = tag.TagString()
+ }
+ return strings.Join(parts, ", ")
+}
+
+func TestPEP425Matches(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ tags []*vpython.Pep425Tag
+ matches []*vpython.Pep425Tag
+ notMatches []*vpython.Pep425Tag
+ }{
+ {
+ tags: nil,
+ notMatches: []*vpython.Pep425Tag{
+ mkTag("", "", ""),
+ mkTag("foo", "bar", "baz"),
+ },
+ },
+ {
+ tags: []*vpython.Pep425Tag{
+ mkTag("fooV", "fooABI", "fooArch"),
iannucci 2017/06/05 19:02:47 it would be nice to use more realistic looking thi
+ mkTag("bazV", "bazABI", "bazArch"),
+ },
+ matches: []*vpython.Pep425Tag{
+ mkTag("fooV", "", ""),
+ mkTag("", "fooABI", ""),
+ mkTag("", "", "fooArch"),
+ mkTag("bazV", "", ""),
+ mkTag("", "bazABI", ""),
+ mkTag("", "", "bazArch"),
+ mkTag("", "fooABI", "fooArch"),
+ },
+ notMatches: []*vpython.Pep425Tag{
+ mkTag("", "", ""),
+ mkTag("fooV", "fooABI", "otherArch"),
+ mkTag("fooV", "fooABI", "bazArch"),
+ },
+ },
+ {
+ tags: []*vpython.Pep425Tag{
+ mkTag("fooV", "fooABI", ""),
+ },
+ matches: []*vpython.Pep425Tag{
+ mkTag("fooV", "fooABI", ""),
+ },
+ notMatches: []*vpython.Pep425Tag{
+ mkTag("", "", ""),
+ mkTag("fooV", "fooABI", "otherArch"),
+ },
+ },
+ }
+
+ Convey(`Test cases for PEP425 tag matching`, t, func() {
+ for _, tc := range testCases {
+ Convey(fmt.Sprintf(`With system tags: %s`, tagString(tc.tags)), func() {
qyearsley 2017/06/05 20:20:08 General question: If the test passes then normally
dnj 2017/06/06 13:59:10 If you run with "-v" for verbose, then the test ca
dnj 2017/06/06 13:59:10 If you run with "-v" for verbose, then the test ca
+ for _, m := range tc.matches {
+ Convey(fmt.Sprintf(`Tag matches: %s`, m.TagString()), func() {
+ So(PEP425Matches(m, tc.tags), ShouldBeTrue)
+ })
+ }
+
+ for _, m := range tc.notMatches {
+ Convey(fmt.Sprintf(`Tag doesn't match: %s`, m.TagString()), func() {
+ So(PEP425Matches(m, tc.tags), ShouldBeFalse)
+ })
+ }
+ })
+ }
+ })
+}
+
+func TestPackageMatches(t *testing.T) {
+ t.Parallel()
+
+ mkPkg := func(name string, tags ...*vpython.Pep425Tag) *vpython.Spec_Package {
+ return &vpython.Spec_Package{
+ Name: name,
+ MatchTag: tags,
+ }
+ }
+
+ testCases := []struct {
+ tags []*vpython.Pep425Tag
+ matchPkgs []*vpython.Spec_Package
+ notMatchPkgs []*vpython.Spec_Package
+ }{
+ {
+ tags: nil,
+ matchPkgs: []*vpython.Spec_Package{
+ mkPkg("NoTags"),
+ },
+ notMatchPkgs: []*vpython.Spec_Package{
+ mkPkg("EmptyMatch", mkTag("", "", "")),
+ mkPkg("MissingMatch", mkTag("foo", "bar", "baz")),
+ },
+ },
+ {
+ tags: []*vpython.Pep425Tag{
+ mkTag("fooV", "fooABI", "fooArch"),
+ mkTag("barV", "barABI", "barArch"),
+ },
+ matchPkgs: []*vpython.Spec_Package{
+ mkPkg("NoTags"),
+ mkPkg("OneMatchingTag", mkTag("fooV", "", "")),
+ mkPkg("MultipleMatchingTag", mkTag("fooV", "", ""), mkTag("", "barABI", "")),
+ },
+ notMatchPkgs: []*vpython.Spec_Package{
+ mkPkg("EmptyMatch", mkTag("", "", "")),
+ mkPkg("MissingMatch", mkTag("none", "none", "none")),
+ },
+ },
+ }
+
+ Convey(`Test cases for package tag matching`, t, func() {
+ for _, tc := range testCases {
+ Convey(fmt.Sprintf(`With system tags: %s`, tagString(tc.tags)), func() {
+ for _, m := range tc.matchPkgs {
+ Convey(fmt.Sprintf(`Package %q matches: %s`, m.Name, tagString(m.MatchTag)), func() {
+ So(PackageMatches(m, tc.tags), ShouldBeTrue)
+ })
+ }
+
+ for _, m := range tc.notMatchPkgs {
+ Convey(fmt.Sprintf(`Package %q doesn't match: %s`, m.Name, tagString(m.MatchTag)), func() {
+ So(PackageMatches(m, tc.tags), ShouldBeFalse)
+ })
+ }
+ })
+ }
+ })
+}
« vpython/spec/match.go ('K') | « vpython/spec/match.go ('k') | vpython/spec/spec.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698