• 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

96.36
/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 {
33✔
35
        return util.Implements[T, model.Updater]()
33✔
36
}
33✔
37

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

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

50
        copiedData = *r.data
103✔
51

103✔
52
        return &copiedData
103✔
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
        if filterPartial == nil && filterDelete == nil && persist {
161✔
60
                // just set the data
77✔
61
                r.data = newData
77✔
62
                return r.data, nil
77✔
63
        }
77✔
64

65
        if !r.SupportsPartialWrite() {
8✔
66
                return nil, model.NewErrorTypeFromString(fmt.Sprintf("partial updates are not supported for type '%s'", util.Type[T]().Name()))
1✔
67
        }
1✔
68

69
        if r.data == nil {
8✔
70
                r.data = new(T)
2✔
71
        }
2✔
72

73
        updater := any(r.data).(model.Updater)
6✔
74
        data, success := updater.UpdateList(remoteWrite, persist, newData, filterPartial, filterDelete)
6✔
75
        if !success {
6✔
NEW
76
                return nil, model.NewErrorTypeFromString("update failed, likely not allowed to write")
×
UNCOV
77
        }
×
78

79
        return data, nil
6✔
80
}
81

82
func (r *FunctionData[T]) DataCopyAny() any {
34✔
83
        return r.DataCopy()
34✔
84
}
34✔
85

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

92
        return data, err
79✔
93
}
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