-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
1 parent
915d0c8
commit b67a662
Showing
5 changed files
with
237 additions
and
68 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
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,30 @@ | ||
package ble | ||
|
||
import "time" | ||
|
||
// bleClientAdaptorOptionApplier needs to be implemented by each configurable option type | ||
type bleClientAdaptorOptionApplier interface { | ||
apply(cfg *bleClientAdaptorConfiguration) | ||
} | ||
|
||
// bleClientAdaptorDebug is the type for applying the debug switch on or off. | ||
type bleClientAdaptorDebugOption bool | ||
|
||
// bleClientAdaptorScanTimeoutOption is the type for applying another timeout than the default 10 min. | ||
type bleClientAdaptorScanTimeoutOption time.Duration | ||
|
||
func (o bleClientAdaptorDebugOption) String() string { | ||
return "debug option for BLE client adaptors" | ||
} | ||
|
||
func (o bleClientAdaptorScanTimeoutOption) String() string { | ||
return "scan timeout option for BLE client adaptors" | ||
} | ||
|
||
func (o bleClientAdaptorDebugOption) apply(cfg *bleClientAdaptorConfiguration) { | ||
cfg.debug = bool(o) | ||
} | ||
|
||
func (o bleClientAdaptorScanTimeoutOption) apply(cfg *bleClientAdaptorConfiguration) { | ||
cfg.scanTimeout = time.Duration(o) | ||
} |
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,27 @@ | ||
package ble | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestWithClientAdaptorDebug(t *testing.T) { | ||
// This is a general test, that options are applied by using the TestWithClientAdaptorDebug() option. | ||
// All other configuration options can also be tested by With..(val).apply(cfg). | ||
// arrange & act | ||
a := NewClientAdaptor("address", WithClientAdaptorDebug()) | ||
// assert | ||
assert.True(t, a.clientCfg.debug) | ||
} | ||
|
||
func TestWithClientAdaptorScanTimeout(t *testing.T) { | ||
// arrange | ||
newTimeout := 2 * time.Second | ||
cfg := &bleClientAdaptorConfiguration{scanTimeout: 10 * time.Second} | ||
// act | ||
WithClientAdaptorScanTimeout(newTimeout).apply(cfg) | ||
// assert | ||
assert.Equal(t, newTimeout, cfg.scanTimeout) | ||
} |
Oops, something went wrong.