本文整理汇总了Golang中github.com/hybridgroup/gobot/gobottest.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Assert函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestExecuteMcpCommand
func TestExecuteMcpCommand(t *testing.T) {
var body interface{}
a := initTestAPI()
// known command
request, _ := http.NewRequest("GET",
"/api/commands/TestFunction",
bytes.NewBufferString(`{"message":"Beep Boop"}`),
)
request.Header.Add("Content-Type", "application/json")
response := httptest.NewRecorder()
a.ServeHTTP(response, request)
json.NewDecoder(response.Body).Decode(&body)
gobottest.Assert(t, body.(map[string]interface{})["result"], "hey Beep Boop")
// unknown command
request, _ = http.NewRequest("GET",
"/api/commands/TestFuntion1",
bytes.NewBufferString(`{"message":"Beep Boop"}`),
)
request.Header.Add("Content-Type", "application/json")
response = httptest.NewRecorder()
a.ServeHTTP(response, request)
json.NewDecoder(response.Body).Decode(&body)
gobottest.Assert(t, body.(map[string]interface{})["error"], "Unknown Command")
}
开发者ID:ympons,项目名称:gobot,代码行数:28,代码来源:api_test.go
示例2: TestSpheroDriverSetDataStreaming
func TestSpheroDriverSetDataStreaming(t *testing.T) {
d := initTestSpheroDriver()
d.SetDataStreaming(DefaultDataStreamingConfig())
data := <-d.packetChannel
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, DefaultDataStreamingConfig())
gobottest.Assert(t, data.body, buf.Bytes())
ret := d.Command("SetDataStreaming")(
map[string]interface{}{
"N": 100.0,
"M": 200.0,
"Mask": 300.0,
"Pcnt": 255.0,
"Mask2": 400.0,
},
)
gobottest.Assert(t, ret, nil)
data = <-d.packetChannel
dconfig := DataStreamingConfig{N: 100, M: 200, Mask: 300, Pcnt: 255, Mask2: 400}
buf = new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, dconfig)
gobottest.Assert(t, data.body, buf.Bytes())
}
开发者ID:nathany,项目名称:gobot,代码行数:29,代码来源:sphero_driver_test.go
示例3: TestRgbLedDriver
func TestRgbLedDriver(t *testing.T) {
var err interface{}
d := initTestRgbLedDriver(newGpioTestAdaptor("adaptor"))
gobottest.Assert(t, d.Name(), "bot")
gobottest.Assert(t, d.Pin(), "r=1, g=2, b=3")
gobottest.Assert(t, d.RedPin(), "1")
gobottest.Assert(t, d.GreenPin(), "2")
gobottest.Assert(t, d.BluePin(), "3")
gobottest.Assert(t, d.Connection().Name(), "adaptor")
testAdaptorDigitalWrite = func() (err error) {
return errors.New("write error")
}
testAdaptorPwmWrite = func() (err error) {
return errors.New("pwm error")
}
err = d.Command("Toggle")(nil)
gobottest.Assert(t, err.(error), errors.New("pwm error"))
err = d.Command("On")(nil)
gobottest.Assert(t, err.(error), errors.New("pwm error"))
err = d.Command("Off")(nil)
gobottest.Assert(t, err.(error), errors.New("pwm error"))
err = d.Command("SetRGB")(map[string]interface{}{"r": 0xff, "g": 0xff, "b": 0xff})
gobottest.Assert(t, err.(error), errors.New("pwm error"))
}
开发者ID:nathany,项目名称:gobot,代码行数:32,代码来源:rgb_led_driver_test.go
示例4: TestJoystickAdaptorConnect
func TestJoystickAdaptorConnect(t *testing.T) {
a := initTestJoystickAdaptor()
gobottest.Assert(t, len(a.Connect()), 0)
a = NewJoystickAdaptor("bot")
gobottest.Assert(t, a.Connect()[0], errors.New("No joystick available"))
}
开发者ID:nathany,项目名称:gobot,代码行数:7,代码来源:joystick_adaptor_test.go
示例5: TestServoConfig
func TestServoConfig(t *testing.T) {
b := New()
b.connection = readWriteCloser{}
tests := []struct {
description string
arguments [3]int
expected []byte
result error
}{
{
description: "Min values for min & max",
arguments: [3]int{9, 0, 0},
expected: []byte{0xF0, 0x70, 9, 0, 0, 0, 0, 0xF7},
},
{
description: "Max values for min & max",
arguments: [3]int{9, 0x3FFF, 0x3FFF},
expected: []byte{0xF0, 0x70, 9, 0x7F, 0x7F, 0x7F, 0x7F, 0xF7},
},
{
description: "Clipped max values for min & max",
arguments: [3]int{9, 0xFFFF, 0xFFFF},
expected: []byte{0xF0, 0x70, 9, 0x7F, 0x7F, 0x7F, 0x7F, 0xF7},
},
}
for _, test := range tests {
testWriteData.Reset()
err := b.ServoConfig(test.arguments[0], test.arguments[1], test.arguments[2])
gobottest.Assert(t, testWriteData.Bytes(), test.expected)
gobottest.Assert(t, err, test.result)
}
}
开发者ID:ympons,项目名称:gobot,代码行数:34,代码来源:client_test.go
示例6: TestConfigureLocator
func TestConfigureLocator(t *testing.T) {
d := initTestSpheroDriver()
d.ConfigureLocator(DefaultLocatorConfig())
data := <-d.packetChannel
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, DefaultLocatorConfig())
gobottest.Assert(t, data.body, buf.Bytes())
ret := d.Command("ConfigureLocator")(
map[string]interface{}{
"Flags": 1.0,
"X": 100.0,
"Y": 100.0,
"YawTare": 0.0,
},
)
gobottest.Assert(t, ret, nil)
data = <-d.packetChannel
lconfig := LocatorConfig{Flags: 1, X: 100, Y: 100, YawTare: 0}
buf = new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, lconfig)
gobottest.Assert(t, data.body, buf.Bytes())
}
开发者ID:nathany,项目名称:gobot,代码行数:27,代码来源:sphero_driver_test.go
示例7: TestMavlinkAdaptorConnect
func TestMavlinkAdaptorConnect(t *testing.T) {
a := initTestMavlinkAdaptor()
gobottest.Assert(t, len(a.Connect()), 0)
a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, errors.New("connect error") }
gobottest.Assert(t, a.Connect()[0], errors.New("connect error"))
}
开发者ID:nathany,项目名称:gobot,代码行数:7,代码来源:mavlink_adaptor_test.go
示例8: TestServoDriverMove
func TestServoDriverMove(t *testing.T) {
d := initTestServoDriver()
d.Move(100)
gobottest.Assert(t, d.CurrentAngle, uint8(100))
err := d.Move(200)
gobottest.Assert(t, err, ErrServoOutOfRange)
}
开发者ID:ympons,项目名称:gobot,代码行数:7,代码来源:servo_driver_test.go
示例9: TestSparkCoreAdaptorDigitalRead
func TestSparkCoreAdaptorDigitalRead(t *testing.T) {
// When HIGH
response := `{"return_value": 1}`
params := []string{"D7"}
a := initTestSparkCoreAdaptor()
testServer := getDummyResponseForPathWithParams("/"+a.DeviceID+"/digitalread", params, response, t)
a.setAPIServer(testServer.URL)
val, _ := a.DigitalRead("D7")
gobottest.Assert(t, val, 1)
testServer.Close()
// When LOW
response = `{"return_value": 0}`
testServer = getDummyResponseForPathWithParams("/"+a.DeviceID+"/digitalread", params, response, t)
a.setAPIServer(testServer.URL)
defer testServer.Close()
val, _ = a.DigitalRead("D7")
gobottest.Assert(t, val, 0)
}
开发者ID:ympons,项目名称:gobot,代码行数:25,代码来源:spark_core_adaptor_test.go
示例10: TestDigisparkAdaptorConnect
func TestDigisparkAdaptorConnect(t *testing.T) {
a := NewDigisparkAdaptor("bot")
gobottest.Assert(t, a.Connect()[0], ErrConnection)
a = initTestDigisparkAdaptor()
gobottest.Assert(t, len(a.Connect()), 0)
}
开发者ID:nathany,项目名称:gobot,代码行数:7,代码来源:digispark_adaptor_test.go
示例11: TestMCP23017DriverGetPort
func TestMCP23017DriverGetPort(t *testing.T) {
// port A
mcp := initTestMCP23017Driver(0)
expectedPort := getBank(0).PortA
actualPort := mcp.getPort("A")
gobottest.Assert(t, expectedPort, actualPort)
// port B
mcp = initTestMCP23017Driver(0)
expectedPort = getBank(0).PortB
actualPort = mcp.getPort("B")
gobottest.Assert(t, expectedPort, actualPort)
// default
mcp = initTestMCP23017Driver(0)
expectedPort = getBank(0).PortA
actualPort = mcp.getPort("")
gobottest.Assert(t, expectedPort, actualPort)
// port A bank 1
mcp = initTestMCP23017Driver(1)
expectedPort = getBank(1).PortA
actualPort = mcp.getPort("")
gobottest.Assert(t, expectedPort, actualPort)
}
开发者ID:ympons,项目名称:gobot,代码行数:25,代码来源:mcp23017_driver_test.go
示例12: TestBlinkMDriverColor
func TestBlinkMDriverColor(t *testing.T) {
blinkM, adaptor := initTestBlinkDriverWithStubbedAdaptor()
// when len(data) is 3
adaptor.i2cReadImpl = func() ([]byte, error) {
return []byte{99, 1, 2}, nil
}
color, _ := blinkM.Color()
gobottest.Assert(t, color, []byte{99, 1, 2})
// when len(data) is not 3
adaptor.i2cReadImpl = func() ([]byte, error) {
return []byte{99}, nil
}
color, _ = blinkM.Color()
gobottest.Assert(t, color, []byte{})
adaptor.i2cWriteImpl = func() error {
return errors.New("write error")
}
color, err := blinkM.Color()
gobottest.Assert(t, err, errors.New("write error"))
}
开发者ID:nathany,项目名称:gobot,代码行数:27,代码来源:blinkm_driver_test.go
示例13: TestBlinkMDriverFirmwareVersion
func TestBlinkMDriverFirmwareVersion(t *testing.T) {
blinkM, adaptor := initTestBlinkDriverWithStubbedAdaptor()
// when len(data) is 2
adaptor.i2cReadImpl = func() ([]byte, error) {
return []byte{99, 1}, nil
}
version, _ := blinkM.FirmwareVersion()
gobottest.Assert(t, version, "99.1")
// when len(data) is not 2
adaptor.i2cReadImpl = func() ([]byte, error) {
return []byte{99}, nil
}
version, _ = blinkM.FirmwareVersion()
gobottest.Assert(t, version, "")
adaptor.i2cWriteImpl = func() error {
return errors.New("write error")
}
version, err := blinkM.FirmwareVersion()
gobottest.Assert(t, err, errors.New("write error"))
}
开发者ID:nathany,项目名称:gobot,代码行数:26,代码来源:blinkm_driver_test.go
示例14: TestDirectPinDriver
func TestDirectPinDriver(t *testing.T) {
var ret map[string]interface{}
var err interface{}
d := initTestDirectPinDriver(newGpioTestAdaptor("adaptor"))
gobottest.Assert(t, d.Name(), "bot")
gobottest.Assert(t, d.Pin(), "1")
gobottest.Assert(t, d.Connection().Name(), "adaptor")
ret = d.Command("DigitalRead")(nil).(map[string]interface{})
gobottest.Assert(t, ret["val"].(int), 1)
gobottest.Assert(t, ret["err"], nil)
err = d.Command("DigitalWrite")(map[string]interface{}{"level": "1"})
gobottest.Assert(t, err.(error), errors.New("write error"))
ret = d.Command("AnalogRead")(nil).(map[string]interface{})
gobottest.Assert(t, ret["val"].(int), 80)
gobottest.Assert(t, ret["err"], nil)
err = d.Command("PwmWrite")(map[string]interface{}{"level": "1"})
gobottest.Assert(t, err.(error), errors.New("write error"))
err = d.Command("ServoWrite")(map[string]interface{}{"level": "1"})
gobottest.Assert(t, err.(error), errors.New("write error"))
}
开发者ID:nathany,项目名称:gobot,代码行数:28,代码来源:direct_pin_driver_test.go
示例15: TestNullReadWriteCloser
func TestNullReadWriteCloser(t *testing.T) {
n := &NullReadWriteCloser{}
i, _ := n.Write([]byte{1, 2, 3})
gobottest.Assert(t, i, 3)
i, _ = n.Read(make([]byte, 10))
gobottest.Assert(t, i, 10)
gobottest.Assert(t, n.Close(), nil)
}
开发者ID:nathany,项目名称:gobot,代码行数:8,代码来源:gobot_test.go
示例16: TestSparkCoreAdaptorPinLevel
func TestSparkCoreAdaptorPinLevel(t *testing.T) {
a := initTestSparkCoreAdaptor()
gobottest.Assert(t, a.pinLevel(1), "HIGH")
gobottest.Assert(t, a.pinLevel(0), "LOW")
gobottest.Assert(t, a.pinLevel(5), "LOW")
}
开发者ID:ympons,项目名称:gobot,代码行数:8,代码来源:spark_core_adaptor_test.go
示例17: TestWiichuckDriverDecode
func TestWiichuckDriverDecode(t *testing.T) {
wii := initTestWiichuckDriver()
gobottest.Assert(t, wii.decode(byte(0)), float64(46))
gobottest.Assert(t, wii.decode(byte(100)), float64(138))
gobottest.Assert(t, wii.decode(byte(200)), float64(246))
gobottest.Assert(t, wii.decode(byte(254)), float64(0))
}
开发者ID:nathany,项目名称:gobot,代码行数:8,代码来源:wiichuck_driver_test.go
示例18: TestWiichuckDriverCalculateJoystickValue
func TestWiichuckDriverCalculateJoystickValue(t *testing.T) {
wii := initTestWiichuckDriver()
gobottest.Assert(t, wii.calculateJoystickValue(float64(20), float64(5)), float64(15))
gobottest.Assert(t, wii.calculateJoystickValue(float64(1), float64(2)), float64(-1))
gobottest.Assert(t, wii.calculateJoystickValue(float64(10), float64(5)), float64(5))
gobottest.Assert(t, wii.calculateJoystickValue(float64(5), float64(10)), float64(-5))
}
开发者ID:nathany,项目名称:gobot,代码行数:8,代码来源:wiichuck_driver_test.go
示例19: TestRgbLedDriverToggle
func TestRgbLedDriverToggle(t *testing.T) {
d := initTestRgbLedDriver(newGpioTestAdaptor("adaptor"))
d.Off()
d.Toggle()
gobottest.Assert(t, d.State(), true)
d.Toggle()
gobottest.Assert(t, d.State(), false)
}
开发者ID:nathany,项目名称:gobot,代码行数:8,代码来源:rgb_led_driver_test.go
示例20: TestButtonDriver
func TestButtonDriver(t *testing.T) {
d := NewButtonDriver(newGpioTestAdaptor("adaptor"), "bot", "1")
gobottest.Assert(t, d.Name(), "bot")
gobottest.Assert(t, d.Connection().Name(), "adaptor")
d = NewButtonDriver(newGpioTestAdaptor("adaptor"), "bot", "1", 30*time.Second)
gobottest.Assert(t, d.interval, 30*time.Second)
}
开发者ID:nathany,项目名称:gobot,代码行数:8,代码来源:button_driver_test.go
注:本文中的github.com/hybridgroup/gobot/gobottest.Assert函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论