• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

enbility / spine-go / 10973819786

21 Sep 2024 03:50PM UTC coverage: 93.707% (+0.2%) from 93.465%
10973819786

push

github

DerAndereAndi
Merge branch 'release/v0.7.0'

626 of 646 new or added lines in 36 files covered. (96.9%)

2 existing lines in 2 files now uncovered.

5018 of 5355 relevant lines covered (93.71%)

88.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.72
/spine/feature_remote.go
1
package spine
2

3
import (
4
        "sync"
5
        "time"
6

7
        "github.com/enbility/ship-go/logging"
8
        "github.com/enbility/spine-go/api"
9
        "github.com/enbility/spine-go/model"
10
        "github.com/enbility/spine-go/util"
11
        "github.com/rickb777/date/period"
12
)
13

14
const defaultMaxResponseDelay = time.Duration(time.Second * 10)
15

16
type FeatureRemote struct {
17
        *Feature
18

19
        entity           api.EntityRemoteInterface
20
        functionDataMap  map[model.FunctionType]api.FunctionDataInterface
21
        maxResponseDelay *time.Duration
22

23
        mux sync.Mutex
24
}
25

26
func NewFeatureRemote(id uint, entity api.EntityRemoteInterface, ftype model.FeatureTypeType, role model.RoleType) *FeatureRemote {
253✔
27
        res := &FeatureRemote{
253✔
28
                Feature: NewFeature(
253✔
29
                        featureAddressType(id, entity.Address()),
253✔
30
                        ftype,
253✔
31
                        role),
253✔
32
                entity:          entity,
253✔
33
                functionDataMap: make(map[model.FunctionType]api.FunctionDataInterface),
253✔
34
        }
253✔
35
        for _, fd := range CreateFunctionData[api.FunctionDataInterface](ftype) {
1,325✔
36
                res.functionDataMap[fd.FunctionType()] = fd
1,072✔
37
        }
1,072✔
38

39
        res.operations = make(map[model.FunctionType]api.OperationsInterface)
253✔
40

253✔
41
        return res
253✔
42
}
43

44
var _ api.FeatureRemoteInterface = (*FeatureRemote)(nil)
45

46
/* FeatureRemoteInterface */
47

48
func (r *FeatureRemote) Device() api.DeviceRemoteInterface {
110✔
49
        return r.entity.Device()
110✔
50
}
110✔
51

52
func (r *FeatureRemote) Entity() api.EntityRemoteInterface {
25✔
53
        return r.entity
25✔
54
}
25✔
55
func (r *FeatureRemote) DataCopy(function model.FunctionType) any {
5✔
56
        r.mux.Lock()
5✔
57
        defer r.mux.Unlock()
5✔
58

5✔
59
        fd := r.functionData(function)
5✔
60
        if fd == nil {
6✔
61
                return nil
1✔
62
        }
1✔
63

64
        return r.functionData(function).DataCopyAny()
4✔
65
}
66

67
func (r *FeatureRemote) UpdateData(persist bool, function model.FunctionType, data any, filterPartial *model.FilterType, filterDelete *model.FilterType) (any, *model.ErrorType) {
6✔
68
        r.mux.Lock()
6✔
69
        defer r.mux.Unlock()
6✔
70

6✔
71
        fd := r.functionData(function)
6✔
72
        if fd == nil {
6✔
NEW
73
                return nil, model.NewErrorTypeFromString("function data not found")
×
74
        }
×
75

76
        return fd.UpdateDataAny(false, persist, data, filterPartial, filterDelete)
6✔
77
}
78

79
func (r *FeatureRemote) SetOperations(functions []model.FunctionPropertyType) {
99✔
80
        r.operations = make(map[model.FunctionType]api.OperationsInterface)
99✔
81
        for _, sf := range functions {
222✔
82
                if sf.PossibleOperations == nil {
123✔
83
                        continue
×
84
                }
85
                r.operations[*sf.Function] = NewOperations(
123✔
86
                        sf.PossibleOperations.Read != nil,
123✔
87
                        sf.PossibleOperations.Read != nil && sf.PossibleOperations.Read.Partial != nil,
123✔
88
                        sf.PossibleOperations.Write != nil,
123✔
89
                        sf.PossibleOperations.Write != nil && sf.PossibleOperations.Write.Partial != nil,
123✔
90
                )
123✔
91
        }
92
}
93

94
func (r *FeatureRemote) SetMaxResponseDelay(delay *model.MaxResponseDelayType) {
31✔
95
        if delay == nil {
62✔
96
                return
31✔
97
        }
31✔
98
        p, err := period.Parse(string(*delay))
×
99
        if err != nil {
×
100
                r.maxResponseDelay = util.Ptr(p.DurationApprox())
×
101
        } else {
×
102
                logging.Log().Debug(err)
×
103
        }
×
104
}
105

106
func (r *FeatureRemote) MaxResponseDelayDuration() time.Duration {
3✔
107
        if r.maxResponseDelay != nil {
3✔
108
                return *r.maxResponseDelay
×
109
        }
×
110
        return defaultMaxResponseDelay
3✔
111
}
112

113
func (r *FeatureRemote) functionData(function model.FunctionType) api.FunctionDataInterface {
15✔
114
        fd, found := r.functionDataMap[function]
15✔
115
        if !found {
16✔
116
                logging.Log().Errorf("Data was not found for function '%s'", function)
1✔
117
                return nil
1✔
118
        }
1✔
119
        return fd
14✔
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc