Skip to content
Permalink
Browse files

Updated testing.go with better comments

  • Loading branch information...
nicklesimba authored and s1061123 committed Jul 15, 2019
1 parent 971396e commit 3c6812e438b09b647e3b0546fcc9fe832db2e589
Showing with 5 additions and 1 deletion.
  1. +5 −1 testing/testing.go
@@ -159,18 +159,20 @@ func EnsureCIDR(cidr string) *net.IPNet {
return net
}

// Implements Result interface
// Result is stub Result for testing
type Result struct {
CNIVersion string `json:"cniVersion,omitempty"`
IP4 *types020.IPConfig `json:"ip4,omitempty"`
IP6 *types020.IPConfig `json:"ip6,omitempty"`
DNS types.DNS `json:"dns,omitempty"`
}

// Version returns current CNIVersion of the given Result
func (r *Result) Version() string {
return r.CNIVersion
}

// GetAsVersion returns a Result object given a version
func (r *Result) GetAsVersion(version string) (types.Result, error) {
for _, supportedVersion := range types020.SupportedVersions {
if version == supportedVersion {
@@ -181,10 +183,12 @@ func (r *Result) GetAsVersion(version string) (types.Result, error) {
return nil, fmt.Errorf("cannot convert version %q to %s", types020.SupportedVersions, version)
}

// Print prints a Result's information to std out
func (r *Result) Print() error {
return r.PrintTo(os.Stdout)
}

// PrintTo prints a Result's information to the provided writer
func (r *Result) PrintTo(writer io.Writer) error {
data, err := json.MarshalIndent(r, "", " ")
if err != nil {

0 comments on commit 3c6812e

Please sign in to comment.
You can’t perform that action at this time.