-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
143 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package annotate | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/paulmach/osm/annotate/internal/core" | ||
) | ||
|
||
func TestMapErrors(t *testing.T) { | ||
e := mapErrors(&core.NoHistoryError{}) | ||
if _, ok := e.(*NoHistoryError); !ok { | ||
t.Errorf("should map NoHistoryError: %+v", e) | ||
} | ||
|
||
e = mapErrors(&core.NoVisibleChildError{}) | ||
if _, ok := e.(*NoVisibleChildError); !ok { | ||
t.Errorf("should map NoVisibleChildError: %+v", e) | ||
} | ||
|
||
err := errors.New("some error") | ||
if e := mapErrors(err); e != err { | ||
t.Errorf("should pass through other errors: %v", e) | ||
} | ||
} |
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,64 @@ | ||
package osmtest | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/paulmach/osm" | ||
) | ||
|
||
func TestScanner(t *testing.T) { | ||
objs := osm.Objects{ | ||
&osm.Node{ID: 1, Version: 4}, | ||
&osm.Way{ID: 2, Version: 5}, | ||
&osm.Relation{ID: 3, Version: 6}, | ||
} | ||
|
||
scanner := NewScanner(objs) | ||
defer scanner.Close() | ||
|
||
expected := osm.ObjectIDs{ | ||
osm.NodeID(1).ObjectID(4), | ||
osm.WayID(2).ObjectID(5), | ||
osm.RelationID(3).ObjectID(6), | ||
} | ||
|
||
ids := osm.ObjectIDs{} | ||
for scanner.Scan() { | ||
ids = append(ids, scanner.Object().ObjectID()) | ||
} | ||
|
||
if !reflect.DeepEqual(ids, expected) { | ||
t.Errorf("incorrect ids: %v", ids) | ||
} | ||
} | ||
|
||
func TestScanner_error(t *testing.T) { | ||
objs := osm.Objects{ | ||
&osm.Node{ID: 1, Version: 4}, | ||
&osm.Way{ID: 2, Version: 5}, | ||
&osm.Relation{ID: 3, Version: 6}, | ||
} | ||
|
||
scanner := NewScanner(objs) | ||
defer scanner.Close() | ||
|
||
if scanner.Err() != nil { | ||
t.Errorf("error should not be set initially") | ||
} | ||
|
||
if !scanner.Scan() { | ||
t.Errorf("should be true initially") | ||
} | ||
|
||
scanner.ScanError = errors.New("some error") | ||
|
||
if scanner.Scan() { | ||
t.Errorf("should be false after error") | ||
} | ||
|
||
if scanner.Err() == nil { | ||
t.Errorf("should return error if there is one") | ||
} | ||
} |