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

Unified Diff: vpython/spec/match_test.go

Issue 2921133002: [vpython] Add conditional packages based on PEP425 (Closed)
Patch Set: rebase Created 3 years, 6 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
« no previous file with comments | « vpython/spec/match.go ('k') | vpython/spec/spec.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b7e9af803d9cda3e690c41a8bc8159df94efec3c
--- /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,
+ }
+}
+
+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("cp27", "cp27mu", "manylinux1_x86_64"),
+ },
+ },
+ {
+ tags: []*vpython.Pep425Tag{
+ mkTag("cp27", "cp27mu", "manylinux1_x86_64"),
+ mkTag("py2", "cp27m", "macosx_10_9_universal"),
+ },
+ matches: []*vpython.Pep425Tag{
+ mkTag("cp27", "", ""),
+ mkTag("", "cp27mu", ""),
+ mkTag("", "", "manylinux1_x86_64"),
+ mkTag("py2", "", ""),
+ mkTag("", "cp27m", ""),
+ mkTag("", "", "macosx_10_9_universal"),
+ mkTag("", "cp27mu", "manylinux1_x86_64"),
+ },
+ notMatches: []*vpython.Pep425Tag{
+ mkTag("", "", ""),
+ mkTag("cp27", "cp27mu", "win_amd64"),
+ mkTag("cp27", "cp27mu", "macosx_10_9_universal"),
+ },
+ },
+ {
+ tags: []*vpython.Pep425Tag{
+ mkTag("cp27", "cp27mu", ""),
+ },
+ matches: []*vpython.Pep425Tag{
+ mkTag("cp27", "cp27mu", ""),
+ },
+ notMatches: []*vpython.Pep425Tag{
+ mkTag("", "", ""),
+ mkTag("cp27", "cp27mu", "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() {
+ 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("cp27", "cp27mu", "manylinux1_x86_64")),
+ },
+ },
+ {
+ tags: []*vpython.Pep425Tag{
+ mkTag("cp27", "cp27mu", "manylinux1_x86_64"),
+ mkTag("py2", "cp27m", "macosx_10_9_universal"),
+ },
+ matchPkgs: []*vpython.Spec_Package{
+ mkPkg("NoTags"),
+ mkPkg("OneMatchingTag", mkTag("cp27", "", "")),
+ mkPkg("MultipleMatchingTag", mkTag("cp27", "", ""), mkTag("", "cp27m", "")),
+ },
+ 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)
+ })
+ }
+ })
+ }
+ })
+}
« no previous file with comments | « vpython/spec/match.go ('k') | vpython/spec/spec.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698