-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a simpler interface for the HTTP request library. (#8862)
- Loading branch information
Showing
18 changed files
with
954 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This module is based in the deprecated library `github.com/gavv/httpexpect`, and contains slightly adaptations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package httpexpect | ||
|
||
// Array provides methods to inspect attached []interface{} object | ||
// (Go representation of JSON array). | ||
type Array struct { | ||
chain chain | ||
value []interface{} | ||
} | ||
|
||
// Iter returns a new slice of Values attached to array elements. | ||
func (a *Array) Iter() []Value { | ||
if a.chain.failed() { | ||
return []Value{} | ||
} | ||
ret := []Value{} | ||
for n := range a.value { | ||
ret = append(ret, Value{a.chain, a.value[n]}) | ||
} | ||
return ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package httpexpect | ||
|
||
type chain struct { | ||
reporter Reporter | ||
failbit bool | ||
} | ||
|
||
func makeChain(reporter Reporter) chain { | ||
return chain{reporter, false} | ||
} | ||
|
||
func (c *chain) failed() bool { | ||
return c.failbit | ||
} | ||
|
||
func (c *chain) fail(message string, args ...interface{}) { | ||
if c.failbit { | ||
return | ||
} | ||
c.failbit = true | ||
c.reporter.Errorf(message, args...) | ||
} | ||
|
||
func (c *chain) reset() { | ||
c.failbit = false | ||
} | ||
|
||
func (c *chain) assertFailed(r Reporter) { | ||
if !c.failbit { | ||
r.Errorf("expected chain is failed, but it's ok") | ||
} | ||
} | ||
|
||
func (c *chain) assertOK(r Reporter) { | ||
if c.failbit { | ||
r.Errorf("expected chain is ok, but it's failed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package httpexpect | ||
|
||
import "net/http" | ||
|
||
// Cookie provides methods to inspect attached http.Cookie value. | ||
type Cookie struct { | ||
chain chain | ||
value *http.Cookie | ||
} | ||
|
||
func (c *Cookie) Raw() *http.Cookie { | ||
return c.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package httpexpect | ||
|
||
// Match provides methods to inspect attached regexp match results. | ||
type Match struct { | ||
chain chain | ||
submatches []string | ||
names map[string]int | ||
} | ||
|
||
func makeMatch(chain chain, submatches []string, names []string) *Match { | ||
if submatches == nil { | ||
submatches = []string{} | ||
} | ||
namemap := map[string]int{} | ||
for n, name := range names { | ||
if name != "" { | ||
namemap[name] = n | ||
} | ||
} | ||
return &Match{chain, submatches, namemap} | ||
} |
Oops, something went wrong.