Skip to content

Commit

Permalink
Merge pull request #12 from nyaruka/remove_resolve
Browse files Browse the repository at this point in the history
Remove Resolve functionality which now lives in goflow's ContactURN
  • Loading branch information
rowanseymour authored May 2, 2018
2 parents 981b096 + 7b4b72e commit cb587f9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 52 deletions.
16 changes: 0 additions & 16 deletions urns/urns.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,6 @@ func (u URN) FacebookRef() string {
return ""
}

// Resolve is called when a URN is part of an excellent expression
func (u URN) Resolve(key string) interface{} {
switch key {
case "display":
return u.Display()
case "path":
return u.Path()
case "scheme":
return u.Scheme()
}
return fmt.Errorf("no field '%s' on URN", key)
}

// Default is called when a URN is part of an excellent expression
func (u URN) Default() interface{} { return u }

// String returns the string representation of this URN
func (u URN) String() string { return string(u) }

Expand Down
36 changes: 0 additions & 36 deletions urns/urns_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package urns

import (
"fmt"
"net/url"
"strings"
"testing"
Expand Down Expand Up @@ -82,41 +81,6 @@ func TestFormat(t *testing.T) {
}
}

func TestResolve(t *testing.T) {
testCases := []struct {
urn URN
key string
hasValue bool
value string
}{
{"facebook:ref:12345", "scheme", true, "facebook"},
{"facebook:ref:12345", "display", true, ""},
{"facebook:ref:12345", "path", true, "ref:12345"},
{"twitter:85114#foobar", "display", true, "foobar"},
{"twitter:85114#foobar", "notkey", false, ""},
}
for _, tc := range testCases {
val := tc.urn.Resolve(tc.key)
err, isErr := val.(error)

if tc.hasValue && isErr {
t.Errorf("Got unexpected error resolving %s for %s: %s", tc.key, tc.urn, err)
}

if !tc.hasValue && !isErr {
t.Errorf("Did not get expected error resolving %s for %s: %s", tc.key, tc.urn, err)
}

if tc.hasValue && tc.value != val {
t.Errorf("Did not get expected value resolving %s for %s. Got %s expected %s", tc.key, tc.urn, val, tc.value)
}

if fmt.Sprintf("%s", tc.urn.Default()) != tc.urn.String() {
t.Errorf("Default value was not string value for %s", tc.urn)
}
}
}

func TestFromParts(t *testing.T) {
testCases := []struct {
scheme string
Expand Down

0 comments on commit cb587f9

Please sign in to comment.