forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more driver and adaptor test coverage
- Loading branch information
Showing
5 changed files
with
77 additions
and
12 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,14 @@ | ||
package gobot | ||
|
||
import "testing" | ||
|
||
func TestAdaptor(t *testing.T) { | ||
a := NewAdaptor("", "testBot", "/dev/null") | ||
Refute(t, a.Name(), "") | ||
a.SetPort("/dev/null1") | ||
Assert(t, a.Port(), "/dev/null1") | ||
a.SetName("myAdaptor") | ||
Assert(t, a.Name(), "myAdaptor") | ||
a.SetConnected(true) | ||
Assert(t, a.Connected(), true) | ||
} |
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,57 @@ | ||
package gobot | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestDriver(t *testing.T) { | ||
a := NewTestAdaptor("testAdaptor") | ||
d := NewDriver("", | ||
"testDriver", | ||
a, | ||
"1", | ||
5*time.Second, | ||
) | ||
|
||
Refute(t, d.Name(), "") | ||
Assert(t, d.Type(), "testDriver") | ||
Assert(t, d.Interval(), 5*time.Second) | ||
Assert(t, d.Pin(), "1") | ||
Assert(t, d.Adaptor(), a) | ||
|
||
d.SetPin("10") | ||
Assert(t, d.Pin(), "10") | ||
|
||
d.SetName("myDriver") | ||
Assert(t, d.Name(), "myDriver") | ||
|
||
d.SetInterval(100 * time.Second) | ||
Assert(t, d.Interval(), 100*time.Second) | ||
|
||
Assert(t, len(d.Commands()), 0) | ||
d.AddCommand("cmd1", func(params map[string]interface{}) interface{} { | ||
return fmt.Sprintf("hello from %v", params["name"]) | ||
}) | ||
Assert(t, len(d.Commands()), 1) | ||
Assert(t, | ||
d.Command("cmd1")(map[string]interface{}{"name": d.Name()}).(string), | ||
"hello from "+d.Name(), | ||
) | ||
|
||
Assert(t, len(d.Events()), 0) | ||
d.AddEvent("event1") | ||
Assert(t, len(d.Events()), 1) | ||
Refute(t, d.Event("event1"), nil) | ||
|
||
defer func() { | ||
r := recover() | ||
if r != nil { | ||
Assert(t, "Unknown Driver Event: event2", r) | ||
} else { | ||
t.Errorf("Did not return Unknown Event error") | ||
} | ||
}() | ||
d.Event("event2") | ||
} |
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