-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into error-vars
- Loading branch information
Showing
5 changed files
with
149 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Package mock offers implementations of interfaces defined in types.go | ||
// This allows complete control over input / output for any given method that consumes | ||
// a given type | ||
package mock | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"github.com/sony/sonyflake/types" | ||
) | ||
|
||
// NewSuccessfulInterfaceAddrs returns a single private IP address | ||
func NewSuccessfulInterfaceAddrs() types.InterfaceAddrs { | ||
ifat := make([]net.Addr, 0, 1) | ||
ifat = append(ifat, &net.IPNet{IP: []byte{192, 168, 0, 1}, Mask: []byte{255, 0, 0, 0}}) | ||
|
||
return func() ([]net.Addr, error) { | ||
return ifat, nil | ||
} | ||
} | ||
|
||
// NewFailingInterfaceAddrs returns an error | ||
func NewFailingInterfaceAddrs() types.InterfaceAddrs { | ||
return func() ([]net.Addr, error) { | ||
return nil, fmt.Errorf("test error") | ||
} | ||
} | ||
|
||
// NewFailingInterfaceAddrs returns an empty slice of addresses | ||
func NewNilInterfaceAddrs() types.InterfaceAddrs { | ||
return func() ([]net.Addr, error) { | ||
return []net.Addr{}, nil | ||
} | ||
} |
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,8 @@ | ||
// Package Types defines type signatures used throughout SonyFlake. This allows for | ||
// fine-tuned control over imports, and the ability to mock out imports as well | ||
package types | ||
|
||
import "net" | ||
|
||
// InterfaceAddrs defines the interface used for retrieving network addresses | ||
type InterfaceAddrs func() ([]net.Addr, error) |