-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vendor: update to latest versions and try to resolve logrus
- Loading branch information
Aeneas Rekkas (arekkas)
committed
Jun 4, 2017
1 parent
62119cd
commit 72fb1fb
Showing
19 changed files
with
458 additions
and
33 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
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,49 @@ | ||
package oauth2 | ||
|
||
import "testing" | ||
import "github.com/oleiade/reflections" | ||
import "github.com/stretchr/testify/assert" | ||
import "github.com/stretchr/testify/require" | ||
|
||
func AssertObjectKeysEqual(t *testing.T, a, b interface{}, keys ...string) { | ||
assert.True(t, len(keys) > 0, "No keys provided.") | ||
for _, k := range keys { | ||
c, err := reflections.GetField(a, k) | ||
assert.Nil(t, err) | ||
d, err := reflections.GetField(b, k) | ||
assert.Nil(t, err) | ||
assert.Equal(t, c, d, "%s", k) | ||
} | ||
} | ||
|
||
func AssertObjectKeysNotEqual(t *testing.T, a, b interface{}, keys ...string) { | ||
assert.True(t, len(keys) > 0, "No keys provided.") | ||
for _, k := range keys { | ||
c, err := reflections.GetField(a, k) | ||
assert.Nil(t, err) | ||
d, err := reflections.GetField(b, k) | ||
assert.Nil(t, err) | ||
assert.NotEqual(t, c, d, "%s", k) | ||
} | ||
} | ||
|
||
func RequireObjectKeysEqual(t *testing.T, a, b interface{}, keys ...string) { | ||
assert.True(t, len(keys) > 0, "No keys provided.") | ||
for _, k := range keys { | ||
c, err := reflections.GetField(a, k) | ||
assert.Nil(t, err) | ||
d, err := reflections.GetField(b, k) | ||
assert.Nil(t, err) | ||
require.Equal(t, c, d, "%s", k) | ||
} | ||
} | ||
func RequireObjectKeysNotEqual(t *testing.T, a, b interface{}, keys ...string) { | ||
assert.True(t, len(keys) > 0, "No keys provided.") | ||
for _, k := range keys { | ||
c, err := reflections.GetField(a, k) | ||
assert.Nil(t, err) | ||
d, err := reflections.GetField(b, k) | ||
assert.Nil(t, err) | ||
require.NotEqual(t, c, d, "%s", k) | ||
} | ||
} |
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,17 @@ | ||
package oauth2 | ||
|
||
import "testing" | ||
|
||
func TestAssertObjectsAreEqualByKeys(t *testing.T) { | ||
type foo struct { | ||
Name string | ||
Body int | ||
} | ||
a := &foo{"foo", 1} | ||
b := &foo{"bar", 1} | ||
c := &foo{"baz", 3} | ||
|
||
AssertObjectKeysEqual(t, a, a, "Name", "Body") | ||
AssertObjectKeysNotEqual(t, a, b, "Name") | ||
AssertObjectKeysNotEqual(t, a, c, "Name", "Body") | ||
} |
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,26 @@ | ||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"path" | ||
) | ||
|
||
func JoinURLStrings(host string, parts ...string) string { | ||
var trailing string | ||
|
||
last := parts[len(parts)-1] | ||
if last[len(last)-1:] == "/" { | ||
trailing = "/" | ||
} | ||
|
||
u, err := url.Parse(host) | ||
if err != nil { | ||
return fmt.Sprintf("%s%s%s", path.Join(append([]string{u.Path}, parts...)...), trailing) | ||
} | ||
|
||
if u.Path == "" { | ||
u.Path = "/" | ||
} | ||
return fmt.Sprintf("%s://%s%s%s", u.Scheme, u.Host, path.Join(append([]string{u.Path}, parts...)...), trailing) | ||
} |
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,33 @@ | ||
package pkg | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestJoinURLStrings(t *testing.T) { | ||
for k, c := range []struct { | ||
give []string | ||
get string | ||
}{ | ||
{ | ||
give: []string{"http://localhost/", "/home"}, | ||
get: "http://localhost/home", | ||
}, | ||
{ | ||
give: []string{"http://localhost", "/home"}, | ||
get: "http://localhost/home", | ||
}, | ||
{ | ||
give: []string{"https://localhost/", "/home"}, | ||
get: "https://localhost/home", | ||
}, | ||
{ | ||
give: []string{"http://localhost/", "/home", "home/", "/home/"}, | ||
get: "http://localhost/home/home/home/", | ||
}, | ||
} { | ||
assert.Equal(t, c.get, JoinURLStrings(c.give[0], c.give[1:]...), "Case %d", k) | ||
} | ||
} |
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,42 @@ | ||
# rand | ||
A library based on crypto/rand to create random sequences, which are cryptographically strong. See: [crypto/rand](http://golang.org/pkg/crypto/rand/) | ||
|
||
## Install | ||
|
||
Run `go get github.com/ory-am/common/rand` | ||
|
||
## Usage | ||
|
||
### Create a random integer | ||
|
||
Create a random integer using [crypto/rand.Read](http://golang.org/pkg/crypto/rand/#Read): | ||
|
||
``` | ||
import "github.com/ory-am/common/rand/numeric" | ||
import "fmt" | ||
func main() { | ||
fmt.Printf("%d", numeric.Int64()) | ||
fmt.Printf("%d", numeric.UInt64()) | ||
fmt.Printf("%d", numeric.Int32()) | ||
fmt.Printf("%d", numeric.UInt32()) | ||
} | ||
``` | ||
|
||
### Create a random rune sequence / string | ||
|
||
Create a random string using [crypto/rand.Read](http://golang.org/pkg/crypto/rand/#Read): | ||
|
||
``` | ||
import "github.com/ory-am/common/rand/sequence" | ||
import "fmt" | ||
func main() { | ||
allowed := []rune("abcdefghijklmnopqrstuvwxyz") | ||
length := 10 | ||
seq, err := sequence.RuneSequence(length, allowed) | ||
fmt.Printf("%s", seq) | ||
fmt.Printf("%s", string(seq)) | ||
} | ||
``` |
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,2 @@ | ||
// A library based on crypto/rand to create random sequences | ||
package rand |
Oops, something went wrong.