Skip to content

Commit 81fa1d2

Browse files
luanbenjaminp
authored andcommitted
Update stretchr/testify and dependencies
Summary: - github.com/stretchr/testify: @commit afd4130c14595c7d37c067f8c883f2b5ec2227e2 (from master) - github.com/stretchr/objx: @commit 477a77ecc69700c7cdeb1fa9e129548e1c1c393c (from v0.1.1) - gopkg.in/yaml.v2: not updated - github.com/pmezard/go-difflib: not updated This bump includes a lot of changes that were between the previous commit of `testify` we vendored (be8372ae8ec5c6daaed3cc28ebf73c54b737c240). It also includes a new change from this [pull-request](stretchr/testify#895) to make failure messages more consistent (especially useful for`proto.Message`s). Test Plan: Changes -> we should make sure we're running all go tests that use testify. GitOrigin-RevId: e88b2e1e997f7ec25df772c27524f17e10b185bc
1 parent e5b1461 commit 81fa1d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+17467
-2667
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
engines:
2+
gofmt:
3+
enabled: true
4+
golint:
5+
enabled: true
6+
govet:
7+
enabled: true
8+
9+
exclude_patterns:
10+
- ".github/"
11+
- "vendor/"
12+
- "codegen/"
13+
- "doc.go"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Module":"github.com/stretchr/objx","Revision":"f269b682246978256a3eb31bef1e5fbd98c4d7f7","Fork":"","Dirty":true}
1+
{"Module":"github.com/stretchr/objx","Revision":"477a77ecc69700c7cdeb1fa9e129548e1c1c393c","Fork":"","Dirty":false}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: go
2+
go:
3+
- 1.8
4+
- 1.9
5+
- tip
6+
7+
env:
8+
global:
9+
- CC_TEST_REPORTER_ID=68feaa3410049ce73e145287acbcdacc525087a30627f96f04e579e75bd71c00
10+
11+
before_script:
12+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13+
- chmod +x ./cc-test-reporter
14+
- ./cc-test-reporter before-build
15+
16+
install:
17+
- go get github.com/go-task/task/cmd/task
18+
19+
script:
20+
- task dl-deps
21+
- task lint
22+
- task test-coverage
23+
24+
after_script:
25+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT

go/src/github.com/stretchr/objx/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dbx_go_library(
77
name = "objx",
88
srcs = [
99
"accessors.go",
10+
"constants.go",
1011
"conversions.go",
1112
"doc.go",
1213
"map.go",

go/src/github.com/stretchr/objx/Gopkg.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[prune]
2+
unused-packages = true
3+
non-go = true
4+
go-tests = true
5+
6+
[[constraint]]
7+
name = "github.com/stretchr/testify"
8+
version = "~1.2.0"

go/src/github.com/stretchr/objx/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ To update Objx to the latest version, run:
7474
go get -u github.com/stretchr/objx
7575

7676
### Supported go versions
77-
We support the lastest four major Go versions, which are 1.6, 1.7, 1.8 and 1.9 at the moment.
77+
We support the lastest two major Go versions, which are 1.8 and 1.9 at the moment.
7878

7979
## Contributing
8080
Please feel free to submit issues, fork the repository and send pull requests!

go/src/github.com/stretchr/objx/Taskfile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ dl-deps:
55
desc: Downloads cli dependencies
66
cmds:
77
- go get -u github.com/golang/lint/golint
8+
- go get -u github.com/golang/dep/cmd/dep
89

910
update-deps:
1011
desc: Updates dependencies

go/src/github.com/stretchr/objx/accessors.go

Lines changed: 93 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,9 @@ import (
66
"strings"
77
)
88

9-
const (
10-
// PathSeparator is the character used to separate the elements
11-
// of the keypath.
12-
//
13-
// For example, `location.address.city`
14-
PathSeparator string = "."
15-
16-
// arrayAccesRegexString is the regex used to extract the array number
17-
// from the access path
18-
arrayAccesRegexString = `^(.+)\[([0-9]+)\]$`
19-
)
9+
// arrayAccesRegexString is the regex used to extract the array number
10+
// from the access path
11+
const arrayAccesRegexString = `^(.+)\[([0-9]+)\]$`
2012

2113
// arrayAccesRegex is the compiled arrayAccesRegexString
2214
var arrayAccesRegex = regexp.MustCompile(arrayAccesRegexString)
@@ -54,60 +46,103 @@ func (m Map) Set(selector string, value interface{}) Map {
5446
return m
5547
}
5648

57-
// getIndex returns the index, which is hold in s by two braches.
58-
// It also returns s withour the index part, e.g. name[1] will return (1, name).
59-
// If no index is found, -1 is returned
60-
func getIndex(s string) (int, string) {
61-
arrayMatches := arrayAccesRegex.FindStringSubmatch(s)
62-
if len(arrayMatches) > 0 {
63-
// Get the key into the map
64-
selector := arrayMatches[1]
65-
// Get the index into the array at the key
66-
// We know this cannt fail because arrayMatches[2] is an int for sure
67-
index, _ := strconv.Atoi(arrayMatches[2])
68-
return index, selector
69-
}
70-
return -1, s
71-
}
72-
7349
// access accesses the object using the selector and performs the
7450
// appropriate action.
75-
func access(current interface{}, selector string, value interface{}, isSet bool) interface{} {
76-
selSegs := strings.SplitN(selector, PathSeparator, 2)
77-
thisSel := selSegs[0]
78-
index := -1
51+
func access(current, selector, value interface{}, isSet bool) interface{} {
52+
switch selector.(type) {
53+
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
54+
if array, ok := current.([]interface{}); ok {
55+
index := intFromInterface(selector)
56+
if index >= len(array) {
57+
return nil
58+
}
59+
return array[index]
60+
}
61+
return nil
7962

80-
if strings.Contains(thisSel, "[") {
81-
index, thisSel = getIndex(thisSel)
82-
}
63+
case string:
64+
selStr := selector.(string)
65+
selSegs := strings.SplitN(selStr, PathSeparator, 2)
66+
thisSel := selSegs[0]
67+
index := -1
68+
var err error
8369

84-
if curMap, ok := current.(Map); ok {
85-
current = map[string]interface{}(curMap)
86-
}
87-
// get the object in question
88-
switch current.(type) {
89-
case map[string]interface{}:
90-
curMSI := current.(map[string]interface{})
91-
if len(selSegs) <= 1 && isSet {
92-
curMSI[thisSel] = value
93-
return nil
70+
if strings.Contains(thisSel, "[") {
71+
arrayMatches := arrayAccesRegex.FindStringSubmatch(thisSel)
72+
if len(arrayMatches) > 0 {
73+
// Get the key into the map
74+
thisSel = arrayMatches[1]
75+
76+
// Get the index into the array at the key
77+
index, err = strconv.Atoi(arrayMatches[2])
78+
79+
if err != nil {
80+
// This should never happen. If it does, something has gone
81+
// seriously wrong. Panic.
82+
panic("objx: Array index is not an integer. Must use array[int].")
83+
}
84+
}
9485
}
95-
current = curMSI[thisSel]
96-
default:
97-
current = nil
98-
}
99-
// do we need to access the item of an array?
100-
if index > -1 {
101-
if array, ok := current.([]interface{}); ok {
102-
if index < len(array) {
103-
current = array[index]
104-
} else {
105-
current = nil
86+
if curMap, ok := current.(Map); ok {
87+
current = map[string]interface{}(curMap)
88+
}
89+
// get the object in question
90+
switch current.(type) {
91+
case map[string]interface{}:
92+
curMSI := current.(map[string]interface{})
93+
if len(selSegs) <= 1 && isSet {
94+
curMSI[thisSel] = value
95+
return nil
10696
}
97+
current = curMSI[thisSel]
98+
default:
99+
current = nil
100+
}
101+
// do we need to access the item of an array?
102+
if index > -1 {
103+
if array, ok := current.([]interface{}); ok {
104+
if index < len(array) {
105+
current = array[index]
106+
} else {
107+
current = nil
108+
}
109+
}
110+
}
111+
if len(selSegs) > 1 {
112+
current = access(current, selSegs[1], value, isSet)
107113
}
108-
}
109-
if len(selSegs) > 1 {
110-
current = access(current, selSegs[1], value, isSet)
111114
}
112115
return current
113116
}
117+
118+
// intFromInterface converts an interface object to the largest
119+
// representation of an unsigned integer using a type switch and
120+
// assertions
121+
func intFromInterface(selector interface{}) int {
122+
var value int
123+
switch selector.(type) {
124+
case int:
125+
value = selector.(int)
126+
case int8:
127+
value = int(selector.(int8))
128+
case int16:
129+
value = int(selector.(int16))
130+
case int32:
131+
value = int(selector.(int32))
132+
case int64:
133+
value = int(selector.(int64))
134+
case uint:
135+
value = int(selector.(uint))
136+
case uint8:
137+
value = int(selector.(uint8))
138+
case uint16:
139+
value = int(selector.(uint16))
140+
case uint32:
141+
value = int(selector.(uint32))
142+
case uint64:
143+
value = int(selector.(uint64))
144+
default:
145+
return 0
146+
}
147+
return value
148+
}

0 commit comments

Comments
 (0)