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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « vpython/spec/match.go ('k') | vpython/spec/spec.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package spec
6
7 import (
8 "fmt"
9 "strings"
10 "testing"
11
12 "github.com/luci/luci-go/vpython/api/vpython"
13
14 . "github.com/smartystreets/goconvey/convey"
15 )
16
17 func mkTag(version, abi, arch string) *vpython.Pep425Tag {
18 return &vpython.Pep425Tag{
19 Version: version,
20 Abi: abi,
21 Arch: arch,
22 }
23 }
24
25 func tagString(tags []*vpython.Pep425Tag) string {
26 parts := make([]string, len(tags))
27 for i, tag := range tags {
28 parts[i] = tag.TagString()
29 }
30 return strings.Join(parts, ", ")
31 }
32
33 func TestPEP425Matches(t *testing.T) {
34 t.Parallel()
35
36 testCases := []struct {
37 tags []*vpython.Pep425Tag
38 matches []*vpython.Pep425Tag
39 notMatches []*vpython.Pep425Tag
40 }{
41 {
42 tags: nil,
43 notMatches: []*vpython.Pep425Tag{
44 mkTag("", "", ""),
45 mkTag("cp27", "cp27mu", "manylinux1_x86_64"),
46 },
47 },
48 {
49 tags: []*vpython.Pep425Tag{
50 mkTag("cp27", "cp27mu", "manylinux1_x86_64"),
51 mkTag("py2", "cp27m", "macosx_10_9_universal"),
52 },
53 matches: []*vpython.Pep425Tag{
54 mkTag("cp27", "", ""),
55 mkTag("", "cp27mu", ""),
56 mkTag("", "", "manylinux1_x86_64"),
57 mkTag("py2", "", ""),
58 mkTag("", "cp27m", ""),
59 mkTag("", "", "macosx_10_9_universal"),
60 mkTag("", "cp27mu", "manylinux1_x86_64"),
61 },
62 notMatches: []*vpython.Pep425Tag{
63 mkTag("", "", ""),
64 mkTag("cp27", "cp27mu", "win_amd64"),
65 mkTag("cp27", "cp27mu", "macosx_10_9_universal") ,
66 },
67 },
68 {
69 tags: []*vpython.Pep425Tag{
70 mkTag("cp27", "cp27mu", ""),
71 },
72 matches: []*vpython.Pep425Tag{
73 mkTag("cp27", "cp27mu", ""),
74 },
75 notMatches: []*vpython.Pep425Tag{
76 mkTag("", "", ""),
77 mkTag("cp27", "cp27mu", "otherArch"),
78 },
79 },
80 }
81
82 Convey(`Test cases for PEP425 tag matching`, t, func() {
83 for _, tc := range testCases {
84 Convey(fmt.Sprintf(`With system tags: %s`, tagString(tc. tags)), func() {
85 for _, m := range tc.matches {
86 Convey(fmt.Sprintf(`Tag matches: %s`, m. TagString()), func() {
87 So(PEP425Matches(m, tc.tags), Sh ouldBeTrue)
88 })
89 }
90
91 for _, m := range tc.notMatches {
92 Convey(fmt.Sprintf(`Tag doesn't match: % s`, m.TagString()), func() {
93 So(PEP425Matches(m, tc.tags), Sh ouldBeFalse)
94 })
95 }
96 })
97 }
98 })
99 }
100
101 func TestPackageMatches(t *testing.T) {
102 t.Parallel()
103
104 mkPkg := func(name string, tags ...*vpython.Pep425Tag) *vpython.Spec_Pac kage {
105 return &vpython.Spec_Package{
106 Name: name,
107 MatchTag: tags,
108 }
109 }
110
111 testCases := []struct {
112 tags []*vpython.Pep425Tag
113 matchPkgs []*vpython.Spec_Package
114 notMatchPkgs []*vpython.Spec_Package
115 }{
116 {
117 tags: nil,
118 matchPkgs: []*vpython.Spec_Package{
119 mkPkg("NoTags"),
120 },
121 notMatchPkgs: []*vpython.Spec_Package{
122 mkPkg("EmptyMatch", mkTag("", "", "")),
123 mkPkg("MissingMatch", mkTag("cp27", "cp27mu", "m anylinux1_x86_64")),
124 },
125 },
126 {
127 tags: []*vpython.Pep425Tag{
128 mkTag("cp27", "cp27mu", "manylinux1_x86_64"),
129 mkTag("py2", "cp27m", "macosx_10_9_universal"),
130 },
131 matchPkgs: []*vpython.Spec_Package{
132 mkPkg("NoTags"),
133 mkPkg("OneMatchingTag", mkTag("cp27", "", "")),
134 mkPkg("MultipleMatchingTag", mkTag("cp27", "", " "), mkTag("", "cp27m", "")),
135 },
136 notMatchPkgs: []*vpython.Spec_Package{
137 mkPkg("EmptyMatch", mkTag("", "", "")),
138 mkPkg("MissingMatch", mkTag("none", "none", "non e")),
139 },
140 },
141 }
142
143 Convey(`Test cases for package tag matching`, t, func() {
144 for _, tc := range testCases {
145 Convey(fmt.Sprintf(`With system tags: %s`, tagString(tc. tags)), func() {
146 for _, m := range tc.matchPkgs {
147 Convey(fmt.Sprintf(`Package %q matches: %s`, m.Name, tagString(m.MatchTag)), func() {
148 So(PackageMatches(m, tc.tags), S houldBeTrue)
149 })
150 }
151
152 for _, m := range tc.notMatchPkgs {
153 Convey(fmt.Sprintf(`Package %q doesn't m atch: %s`, m.Name, tagString(m.MatchTag)), func() {
154 So(PackageMatches(m, tc.tags), S houldBeFalse)
155 })
156 }
157 })
158 }
159 })
160 }
OLDNEW
« 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