Skip to content

Commit 07a44ec

Browse files
authored
Implicit optional dependencies (#4963)
1 parent 6cb7182 commit 07a44ec

File tree

90 files changed

+1475
-503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1475
-503
lines changed

.github/workflows/motion-tests.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ jobs:
5555

5656
- name: Run motion tests on PR branch
5757
shell: bash
58-
env:
58+
env:
5959
URL: ${{ github.event.pull_request.head.repo.html_url }}
6060
SHA: ${{ github.event.pull_request.head.sha }}
6161
run: |
62-
cd motion-testing
63-
go mod edit -replace go.viam.com/rdk=${URL#"https://"}@$SHA
64-
sudo -Hu testbot bash -lc "go mod tidy && go test ./... -v -run TestMotionExtended"
62+
echo "Skipping actual running of extended motion tests until RSDK-10651 has been resolved"
63+
# cd motion-testing
64+
# go mod edit -replace go.viam.com/rdk=${URL#"https://"}@$SHA
65+
# sudo -Hu testbot bash -lc "go mod tidy && go test ./... -v -run TestMotionExtended"

cli/module_generate/_templates/go/tmpl-module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ type Config struct {
3838
// Returns implicit dependencies based on the config.
3939
// The path is the JSON path in your robot's config (not the `Config` struct) to the
4040
// resource being validated; e.g. "components.0".
41-
func (cfg *Config) Validate(path string) ([]string, error) {
41+
func (cfg *Config) Validate(path string) ([]string, []string, error) {
4242
// Add config validation code here
43-
return nil, nil
43+
return nil, nil, nil
4444
}
4545

4646
type {{.ModuleCamel}}{{.ModelPascal}} struct {

components/arm/fake/fake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Config struct {
4040
}
4141

4242
// Validate ensures all parts of the config are valid.
43-
func (conf *Config) Validate(path string) ([]string, error) {
43+
func (conf *Config) Validate(path string) ([]string, []string, error) {
4444
var err error
4545
switch {
4646
case conf.ArmModel != "" && conf.ModelFilePath != "":
@@ -50,7 +50,7 @@ func (conf *Config) Validate(path string) ([]string, error) {
5050
case conf.ArmModel == "" && conf.ModelFilePath != "":
5151
_, err = modelFromPath(conf.ModelFilePath, "")
5252
}
53-
return nil, err
53+
return nil, nil, err
5454
}
5555

5656
func init() {

components/arm/universalrobots/ur.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ type Config struct {
4747
}
4848

4949
// Validate ensures all parts of the config are valid.
50-
func (cfg *Config) Validate(path string) ([]string, error) {
50+
func (cfg *Config) Validate(path string) ([]string, []string, error) {
5151
if cfg.Host == "" {
52-
return nil, resource.NewConfigValidationFieldRequiredError(path, "host")
52+
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "host")
5353
}
5454
if cfg.SpeedDegsPerSec > 180 || cfg.SpeedDegsPerSec < 3 {
55-
return nil, errors.New("speed for universalrobots has to be between 3 and 180 degrees per second")
55+
return nil, nil, errors.New("speed for universalrobots has to be between 3 and 180 degrees per second")
5656
}
57-
return []string{}, nil
57+
return []string{}, nil, nil
5858
}
5959

6060
//go:embed ur5e.json

components/arm/wrapper/wrapper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ type Config struct {
2626
var model = resource.DefaultModelFamily.WithModel("wrapper_arm")
2727

2828
// Validate ensures all parts of the config are valid.
29-
func (cfg *Config) Validate(path string) ([]string, error) {
29+
func (cfg *Config) Validate(path string) ([]string, []string, error) {
3030
var deps []string
3131
if cfg.ArmName == "" {
32-
return nil, resource.NewConfigValidationFieldRequiredError(path, "arm-name")
32+
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "arm-name")
3333
}
3434
if _, err := modelFromPath(cfg.ModelFilePath, ""); err != nil {
35-
return nil, err
35+
return nil, nil, err
3636
}
3737
deps = append(deps, cfg.ArmName)
38-
return deps, nil
38+
return deps, nil, nil
3939
}
4040

4141
func init() {

components/base/sensorcontrolled/sensorcontrolled.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ type Config struct {
4545
}
4646

4747
// Validate validates all parts of the sensor controlled base config.
48-
func (cfg *Config) Validate(path string) ([]string, error) {
48+
func (cfg *Config) Validate(path string) ([]string, []string, error) {
4949
deps := []string{}
5050
if len(cfg.MovementSensor) == 0 {
51-
return nil, resource.NewConfigValidationError(path, errors.New("need at least one movement sensor for base"))
51+
return nil, nil, resource.NewConfigValidationError(path, errors.New("need at least one movement sensor for base"))
5252
}
5353
deps = append(deps, cfg.MovementSensor...)
5454

5555
if cfg.Base == "" {
56-
return nil, resource.NewConfigValidationFieldRequiredError(path, "base")
56+
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "base")
5757
}
5858
deps = append(deps, cfg.Base)
5959

6060
for _, pidConf := range cfg.ControlParameters {
6161
if pidConf.Type != typeLinVel && pidConf.Type != typeAngVel {
62-
return nil, resource.NewConfigValidationError(path,
62+
return nil, nil, resource.NewConfigValidationError(path,
6363
errors.New("control_parameters type must be 'linear_velocity' or 'angular_velocity'"))
6464
}
6565
}
6666

67-
return deps, nil
67+
return deps, nil, nil
6868
}
6969

7070
type sensorBase struct {

components/base/sensorcontrolled/sensorcontrolled_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestSensorBase(t *testing.T) {
115115
testCfg := sConfig()
116116
conf, ok := testCfg.ConvertedAttributes.(*Config)
117117
test.That(t, ok, test.ShouldBeTrue)
118-
deps, err := conf.Validate("path")
118+
deps, _, err := conf.Validate("path")
119119
test.That(t, err, test.ShouldBeNil)
120120
test.That(t, deps, test.ShouldResemble, []string{"ms", "test_base"})
121121
sbDeps := createDependencies(t)

components/base/wheeled/wheeled_base.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,34 @@ type Config struct {
6363
}
6464

6565
// Validate ensures all parts of the config are valid.
66-
func (cfg *Config) Validate(path string) ([]string, error) {
66+
func (cfg *Config) Validate(path string) ([]string, []string, error) {
6767
var deps []string
6868

6969
if cfg.WidthMM == 0 {
70-
return nil, resource.NewConfigValidationFieldRequiredError(path, "width_mm")
70+
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "width_mm")
7171
}
7272

7373
if cfg.WheelCircumferenceMM == 0 {
74-
return nil, resource.NewConfigValidationFieldRequiredError(path, "wheel_circumference_mm")
74+
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "wheel_circumference_mm")
7575
}
7676

7777
if len(cfg.Left) == 0 {
78-
return nil, resource.NewConfigValidationFieldRequiredError(path, "left")
78+
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "left")
7979
}
8080
if len(cfg.Right) == 0 {
81-
return nil, resource.NewConfigValidationFieldRequiredError(path, "right")
81+
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "right")
8282
}
8383

8484
if len(cfg.Left) != len(cfg.Right) {
85-
return nil, resource.NewConfigValidationError(path,
85+
return nil, nil, resource.NewConfigValidationError(path,
8686
fmt.Errorf("left and right need to have the same number of motors, not %d vs %d",
8787
len(cfg.Left), len(cfg.Right)))
8888
}
8989

9090
deps = append(deps, cfg.Left...)
9191
deps = append(deps, cfg.Right...)
9292

93-
return deps, nil
93+
return deps, nil, nil
9494
}
9595

9696
func init() {

components/base/wheeled/wheeled_base_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestWheelBaseMath(t *testing.T) {
7171
ctx := context.Background()
7272
logger := logging.NewTestLogger(t)
7373
testCfg := newTestCfg()
74-
deps, err := testCfg.Validate("path", resource.APITypeComponentName)
74+
deps, _, err := testCfg.Validate("path", resource.APITypeComponentName)
7575
test.That(t, err, test.ShouldBeNil)
7676
motorDeps := fakeMotorDependencies(t, deps)
7777

@@ -350,7 +350,7 @@ func TestWheeledBaseConstructor(t *testing.T) {
350350

351351
// empty config
352352
cfg := &Config{}
353-
_, err := cfg.Validate("path")
353+
_, _, err := cfg.Validate("path")
354354
test.That(t, err, test.ShouldNotBeNil)
355355

356356
// invalid config
@@ -360,12 +360,12 @@ func TestWheeledBaseConstructor(t *testing.T) {
360360
Left: []string{"fl-m", "bl-m"},
361361
Right: []string{"fr-m"},
362362
}
363-
_, err = cfg.Validate("path")
363+
_, _, err = cfg.Validate("path")
364364
test.That(t, err, test.ShouldNotBeNil)
365365

366366
// valid config
367367
testCfg := newTestCfg()
368-
deps, err := testCfg.Validate("path", resource.APITypeComponentName)
368+
deps, _, err := testCfg.Validate("path", resource.APITypeComponentName)
369369
test.That(t, err, test.ShouldBeNil)
370370
motorDeps := fakeMotorDependencies(t, deps)
371371

@@ -384,7 +384,7 @@ func TestWheeledBaseReconfigure(t *testing.T) {
384384

385385
// valid config
386386
testCfg := newTestCfg()
387-
deps, err := testCfg.Validate("path", resource.APITypeComponentName)
387+
deps, _, err := testCfg.Validate("path", resource.APITypeComponentName)
388388
test.That(t, err, test.ShouldBeNil)
389389
motorDeps := fakeMotorDependencies(t, deps)
390390

@@ -404,7 +404,7 @@ func TestWheeledBaseReconfigure(t *testing.T) {
404404
Left: []string{"fr-m", "br-m"},
405405
Right: []string{"fl-m", "bl-m"},
406406
}
407-
deps, err = newTestConf.Validate("path", resource.APITypeComponentName)
407+
deps, _, err = newTestConf.Validate("path", resource.APITypeComponentName)
408408
test.That(t, err, test.ShouldBeNil)
409409
motorDeps = fakeMotorDependencies(t, deps)
410410
test.That(t, wb.Reconfigure(ctx, motorDeps, newTestConf), test.ShouldBeNil)
@@ -418,7 +418,7 @@ func TestWheeledBaseReconfigure(t *testing.T) {
418418
Right: []string{"fr-m", "br-m"},
419419
}
420420

421-
deps, err = newerTestCfg.Validate("path", resource.APITypeComponentName)
421+
deps, _, err = newerTestCfg.Validate("path", resource.APITypeComponentName)
422422
test.That(t, err.Error(), test.ShouldContainSubstring, "left and right need to have the same number of motors")
423423
test.That(t, deps, test.ShouldBeNil)
424424

@@ -432,40 +432,40 @@ func TestWheeledBaseReconfigure(t *testing.T) {
432432
Right: []string{"fr-m", "br-m", "mr-m"},
433433
}
434434

435-
deps, err = newestTestCfg.Validate("path", resource.APITypeComponentName)
435+
deps, _, err = newestTestCfg.Validate("path", resource.APITypeComponentName)
436436
test.That(t, err, test.ShouldBeNil)
437437
motorDeps = fakeMotorDependencies(t, deps)
438438
test.That(t, wb.Reconfigure(ctx, motorDeps, newestTestCfg), test.ShouldBeNil)
439439
}
440440

441441
func TestValidate(t *testing.T) {
442442
cfg := &Config{}
443-
deps, err := cfg.Validate("path")
443+
deps, _, err := cfg.Validate("path")
444444
test.That(t, deps, test.ShouldBeNil)
445445
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "width_mm")
446446

447447
cfg.WidthMM = 100
448-
deps, err = cfg.Validate("path")
448+
deps, _, err = cfg.Validate("path")
449449
test.That(t, deps, test.ShouldBeNil)
450450
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "wheel_circumference_mm")
451451

452452
cfg.WheelCircumferenceMM = 1000
453-
deps, err = cfg.Validate("path")
453+
deps, _, err = cfg.Validate("path")
454454
test.That(t, deps, test.ShouldBeNil)
455455
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "left")
456456

457457
cfg.Left = []string{"fl-m", "bl-m"}
458-
deps, err = cfg.Validate("path")
458+
deps, _, err = cfg.Validate("path")
459459
test.That(t, deps, test.ShouldBeNil)
460460
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "right")
461461

462462
cfg.Right = []string{"fr-m"}
463-
deps, err = cfg.Validate("path")
463+
deps, _, err = cfg.Validate("path")
464464
test.That(t, deps, test.ShouldBeNil)
465465
test.That(t, err.Error(), test.ShouldContainSubstring, "left and right need to have the same number of motors, not 2 vs 1")
466466

467467
cfg.Right = append(cfg.Right, "br-m")
468-
deps, err = cfg.Validate("path")
468+
deps, _, err = cfg.Validate("path")
469469
test.That(t, deps, test.ShouldResemble, []string{"fl-m", "bl-m", "fr-m", "br-m"})
470470
test.That(t, err, test.ShouldBeNil)
471471
}

components/board/esp32/board.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func init() {
5454
}
5555

5656
// Validate for esp32 will always return an unsupported error.
57-
func (conf *Config) Validate(path string) ([]string, error) {
58-
return []string{}, errUnsupported
57+
func (conf *Config) Validate(path string) ([]string, []string, error) {
58+
return []string{}, nil, errUnsupported
5959
}
6060

6161
func newEsp32Board(

components/board/fake/board.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ type Config struct {
3838
}
3939

4040
// Validate ensures all parts of the config are valid.
41-
func (conf *Config) Validate(path string) ([]string, error) {
41+
func (conf *Config) Validate(path string) ([]string, []string, error) {
4242
for idx, conf := range conf.AnalogReaders {
4343
if err := conf.Validate(fmt.Sprintf("%s.%s.%d", path, "analogs", idx)); err != nil {
44-
return nil, err
44+
return nil, nil, err
4545
}
4646
}
4747
for idx, conf := range conf.DigitalInterrupts {
4848
if err := conf.Validate(fmt.Sprintf("%s.%s.%d", path, "digital_interrupts", idx)); err != nil {
49-
return nil, err
49+
return nil, nil, err
5050
}
5151
}
5252

5353
if conf.FailNew {
54-
return nil, errors.New("whoops")
54+
return nil, nil, errors.New("whoops")
5555
}
5656

57-
return nil, nil
57+
return nil, nil, nil
5858
}
5959

6060
var model = resource.DefaultModelFamily.WithModel("fake")

components/board/fake/board_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,28 @@ func TestConfigValidate(t *testing.T) {
4646
validConfig := Config{}
4747

4848
validConfig.AnalogReaders = []board.AnalogReaderConfig{{}}
49-
_, err := validConfig.Validate("path")
49+
_, _, err := validConfig.Validate("path")
5050
test.That(t, err, test.ShouldNotBeNil)
5151
test.That(t, err.Error(), test.ShouldContainSubstring, `path.analogs.0`)
5252
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "name")
5353

5454
validConfig.AnalogReaders = []board.AnalogReaderConfig{{Name: "bar"}}
55-
_, err = validConfig.Validate("path")
55+
_, _, err = validConfig.Validate("path")
5656
test.That(t, err, test.ShouldBeNil)
5757

5858
validConfig.DigitalInterrupts = []board.DigitalInterruptConfig{{}}
59-
_, err = validConfig.Validate("path")
59+
_, _, err = validConfig.Validate("path")
6060
test.That(t, err, test.ShouldNotBeNil)
6161
test.That(t, err.Error(), test.ShouldContainSubstring, `path.digital_interrupts.0`)
6262
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "name")
6363

6464
validConfig.DigitalInterrupts = []board.DigitalInterruptConfig{{Name: "bar"}}
65-
_, err = validConfig.Validate("path")
65+
_, _, err = validConfig.Validate("path")
6666
test.That(t, err, test.ShouldNotBeNil)
6767
test.That(t, err.Error(), test.ShouldContainSubstring, `path.digital_interrupts.0`)
6868
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "pin")
6969

7070
validConfig.DigitalInterrupts = []board.DigitalInterruptConfig{{Name: "bar", Pin: "3"}}
71-
_, err = validConfig.Validate("path")
71+
_, _, err = validConfig.Validate("path")
7272
test.That(t, err, test.ShouldBeNil)
7373
}

components/board/genericlinux/board_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,29 @@ func TestConfigValidate(t *testing.T) {
5858
validConfig := Config{}
5959

6060
validConfig.AnalogReaders = []mcp3008helper.MCP3008AnalogConfig{{}}
61-
_, err := validConfig.Validate("path")
61+
_, _, err := validConfig.Validate("path")
6262
test.That(t, err, test.ShouldNotBeNil)
6363
test.That(t, err.Error(), test.ShouldContainSubstring, `path.analogs.0`)
6464
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "name")
6565

6666
validConfig.AnalogReaders = []mcp3008helper.MCP3008AnalogConfig{{Name: "bar"}}
67-
_, err = validConfig.Validate("path")
67+
_, _, err = validConfig.Validate("path")
6868
test.That(t, err, test.ShouldBeNil)
6969

7070
validConfig.DigitalInterrupts = []board.DigitalInterruptConfig{{}}
71-
_, err = validConfig.Validate("path")
71+
_, _, err = validConfig.Validate("path")
7272
test.That(t, err, test.ShouldNotBeNil)
7373
test.That(t, err.Error(), test.ShouldContainSubstring, `path.digital_interrupts.0`)
7474
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "name")
7575

7676
validConfig.DigitalInterrupts = []board.DigitalInterruptConfig{{Name: "bar"}}
77-
_, err = validConfig.Validate("path")
77+
_, _, err = validConfig.Validate("path")
7878
test.That(t, err, test.ShouldNotBeNil)
7979
test.That(t, err.Error(), test.ShouldContainSubstring, `path.digital_interrupts.0`)
8080
test.That(t, resource.GetFieldFromFieldRequiredError(err), test.ShouldEqual, "pin")
8181

8282
validConfig.DigitalInterrupts = []board.DigitalInterruptConfig{{Name: "bar", Pin: "3"}}
83-
_, err = validConfig.Validate("path")
83+
_, _, err = validConfig.Validate("path")
8484
test.That(t, err, test.ShouldBeNil)
8585
}
8686

0 commit comments

Comments
 (0)