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

enbility / spine-go / 13110736334

03 Feb 2025 09:50AM UTC coverage: 93.436% (-0.3%) from 93.689%
13110736334

Pull #52

github

web-flow
Merge f90fdf5cf into 5fb9ea129
Pull Request #52: Fix merge of spine data types when messages arrive with unset identifiers

53 of 69 new or added lines in 2 files covered. (76.81%)

1 existing line in 1 file now uncovered.

5096 of 5454 relevant lines covered (93.44%)

93.74 hits per line

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

93.22
/spine/function_data.go
1
package spine
2

3
import (
4
        "fmt"
5
        "sync"
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
)
12

13
type FunctionData[T any] struct {
14
        functionType model.FunctionType
15
        data         *T
16

17
        mux sync.Mutex
18
}
19

20
func NewFunctionData[T any](function model.FunctionType) *FunctionData[T] {
1,932✔
21
        return &FunctionData[T]{
1,932✔
22
                functionType: function,
1,932✔
23
        }
1,932✔
24
}
1,932✔
25

26
var _ api.FunctionDataInterface = (*FunctionData[int])(nil)
27

28
/* FunctionDataInterface */
29

30
func (r *FunctionData[T]) FunctionType() model.FunctionType {
1,756✔
31
        return r.functionType
1,756✔
32
}
1,756✔
33

34
func (r *FunctionData[T]) SupportsPartialWrite() bool {
116✔
35
        return util.Implements[T, model.Updater]()
116✔
36
}
116✔
37

38
func (r *FunctionData[T]) DataCopy() *T {
117✔
39
        r.mux.Lock()
117✔
40
        defer r.mux.Unlock()
117✔
41

117✔
42
        // copy the data and return it as the data can be updated
117✔
43
        // and newly assigned at any time otherwise we run into panics
117✔
44
        // because of invalid memory address or nil pointer dereference
117✔
45
        var copiedData T
117✔
46
        if r.data == nil {
130✔
47
                return nil
13✔
48
        }
13✔
49

50
        copiedData = *r.data
104✔
51

104✔
52
        return &copiedData
104✔
53
}
54

55
func (r *FunctionData[T]) UpdateData(remoteWrite, persist bool, newData *T, filterPartial *model.FilterType, filterDelete *model.FilterType) (any, *model.ErrorType) {
84✔
56
        r.mux.Lock()
84✔
57
        defer r.mux.Unlock()
84✔
58

84✔
59
        // Only non list data is handled here
84✔
60
        if filterPartial == nil && filterDelete == nil && persist && !r.SupportsPartialWrite() {
155✔
61
                if model.HasAllIdentifiers(newData) {
142✔
62
                        // just set the data
71✔
63
                        r.data = newData
71✔
64
                        return r.data, nil
71✔
65
                }
71✔
NEW
66
                logging.Log().Debug("incoming new data of type '%s' does not have all identifiers set, leaving old data unchanged", util.Type[T]().Name())
×
UNCOV
67
                return r.data, nil
×
68
        }
69

70
        if !r.SupportsPartialWrite() {
14✔
71
                return nil, model.NewErrorTypeFromString(fmt.Sprintf("partial updates are not supported for type '%s'", util.Type[T]().Name()))
1✔
72
        }
1✔
73

74
        if r.data == nil {
19✔
75
                r.data = new(T)
7✔
76
        }
7✔
77

78
        updater := any(r.data).(model.Updater)
12✔
79
        data, success := updater.UpdateList(remoteWrite, persist, newData, filterPartial, filterDelete)
12✔
80
        if !success {
12✔
81
                return nil, model.NewErrorTypeFromString("update failed, likely not allowed to write")
×
82
        }
×
83

84
        return data, nil
12✔
85
}
86

87
func (r *FunctionData[T]) DataCopyAny() any {
35✔
88
        return r.DataCopy()
35✔
89
}
35✔
90

91
func (r *FunctionData[T]) UpdateDataAny(remoteWrite, persist bool, newData any, filterPartial *model.FilterType, filterDelete *model.FilterType) (any, *model.ErrorType) {
79✔
92
        data, err := r.UpdateData(remoteWrite, persist, newData.(*T), filterPartial, filterDelete)
79✔
93
        if err != nil {
80✔
94
                logging.Log().Debug(err.String())
1✔
95
        }
1✔
96

97
        return data, err
79✔
98
}
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

© 2026 Coveralls, Inc