Skip to content
Snippets Groups Projects
Commit 4909dd00 authored by Zygmunt Krynicki's avatar Zygmunt Krynicki
Browse files

dbusutil/dbustest: add tests for TestBus and Suite


Test helpers are just code that also needs to be tested. Add smoke test
for TestBus and for the Suite types.

Signed-off-by: default avatarZygmunt Krynicki <zygmunt.krynicki@huawei.com>
parent ea3de9ef
No related branches found
No related tags found
No related merge requests found
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Huawei Inc.
package dbustest_test
import (
"fmt"
"os"
"os/exec"
"strings"
"testing"
. "gopkg.in/check.v1"
"git.ostc-eu.org/OSTC/OHOS/components/sysota/dbusutil/dbustest"
)
func Test(t *testing.T) { TestingT(t) }
type testbusSuite struct{}
var _ = Suite(&testbusSuite{})
func (s *testbusSuite) TestNewTestBus(c *C) {
_, err := exec.LookPath("dbus-daemon")
if err != nil {
c.Skip(fmt.Sprintf("cannot initialize TestBus: %v", err))
}
bus, err := dbustest.NewTestBus()
c.Assert(err, IsNil)
defer func() {
c.Check(bus.Close(), IsNil)
}()
addr := bus.BusAddress()
c.Check(strings.HasPrefix(addr, "unix:path=/tmp/test-bus-"), Equals, true)
}
func (s *testbusSuite) TestSetDBusSystemBusAddress(c *C) {
restore, err := dbustest.SetDBusSystemBusAddress("potato")
c.Assert(err, IsNil)
defer func() {
c.Assert(restore(), IsNil)
}()
c.Check(os.Getenv("DBUS_SYSTEM_BUS_ADDRESS"), Equals, "potato")
}
type suiteSuite struct {
dbustest.Suite
}
var _ = Suite(&suiteSuite{})
func (s *suiteSuite) TestSystemBusAddress(c *C) {
// Tests see a test system bus.
addr := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS")
c.Check(strings.HasPrefix(addr, "unix:path=/tmp/test-bus-"), Equals, true)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment