• 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

88.98
/model/nodemanagement_additions.go
1
package model
2

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

7
        "github.com/enbility/spine-go/util"
8
)
9

10
var nmMux sync.Mutex
11

12
// NodeManagementDestinationListDataType
13

14
var _ Updater = (*NodeManagementDestinationListDataType)(nil)
15

NEW
16
func (r *NodeManagementDestinationListDataType) UpdateList(remoteWrite, persist bool, newList any, filterPartial, filterDelete *FilterType) (any, bool) {
×
17
        var newData []NodeManagementDestinationDataType
×
18
        if newList != nil {
×
19
                newData = newList.(*NodeManagementDestinationListDataType).NodeManagementDestinationData
×
20
        }
×
21

22
        data, success := UpdateList(remoteWrite, r.NodeManagementDestinationData, newData, filterPartial, filterDelete)
×
23

×
NEW
24
        if success && persist {
×
25
                r.NodeManagementDestinationData = data
×
26
        }
×
27

NEW
28
        return data, success
×
29
}
30

31
// NodeManagementUseCaseDataType
32

33
// find the matching UseCaseInformation index for
34
// a given FeatureAddressType, UseCaseActorType and UseCaseNameType
35
//
36
// if UseCaseActorType and UseCaseNameType are empty they are ignored,
37
// and the first matching UseCaseInformation item is returned
38
func (n *NodeManagementUseCaseDataType) useCaseInformationIndex(
39
        address FeatureAddressType,
40
        actor UseCaseActorType,
41
        useCaseName UseCaseNameType,
42
) (int, bool) {
14✔
43
        // get the element with the same entity
14✔
44
        for index, item := range n.UseCaseInformation {
30✔
45
                if item.Address.Device == nil ||
16✔
46
                        item.Address.Entity == nil ||
16✔
47
                        !reflect.DeepEqual(item.Address.Device, address.Device) ||
16✔
48
                        !reflect.DeepEqual(item.Address.Entity, address.Entity) {
17✔
49
                        continue
1✔
50
                }
51

52
                if len(actor) == 0 && len(useCaseName) == 0 {
16✔
53
                        return index, true
1✔
54
                }
1✔
55

56
                if len(actor) > 0 {
28✔
57
                        if item.Actor == nil || *item.Actor != actor {
18✔
58
                                continue
4✔
59
                        }
60
                }
61

62
                if len(useCaseName) == 0 {
13✔
63
                        return index, true
3✔
64
                }
3✔
65

66
                if _, ok := item.useCaseSupportIndex(useCaseName); ok {
11✔
67
                        return index, true
4✔
68
                }
4✔
69
        }
70

71
        return -1, false
6✔
72
}
73

74
// add a new UseCaseSupportType
75
func (n *NodeManagementUseCaseDataType) AddUseCaseSupport(
76
        address FeatureAddressType,
77
        actor UseCaseActorType,
78
        useCaseName UseCaseNameType,
79
        useCaseVersion SpecificationVersionType,
80
        useCaseDocumemtSubRevision string,
81
        useCaseAvailable bool,
82
        scenarios []UseCaseScenarioSupportType,
83
) {
5✔
84
        nmMux.Lock()
5✔
85
        defer nmMux.Unlock()
5✔
86

5✔
87
        useCaseSupport := UseCaseSupportType{
5✔
88
                UseCaseName:                &useCaseName,
5✔
89
                UseCaseVersion:             &useCaseVersion,
5✔
90
                UseCaseAvailable:           &useCaseAvailable,
5✔
91
                ScenarioSupport:            scenarios,
5✔
92
                UseCaseDocumentSubRevision: &useCaseDocumemtSubRevision,
5✔
93
        }
5✔
94

5✔
95
        // is there an entry for the entity address and actor
5✔
96
        usecaseIndex, ok := n.useCaseInformationIndex(address, actor, "")
5✔
97

5✔
98
        if ok {
8✔
99
                n.UseCaseInformation[usecaseIndex].Add(useCaseSupport)
3✔
100
        } else {
5✔
101
                // create a new element for this entity
2✔
102
                useCaseInformation := UseCaseInformationDataType{
2✔
103
                        Address: &FeatureAddressType{
2✔
104
                                Device: address.Device,
2✔
105
                                Entity: address.Entity,
2✔
106
                        },
2✔
107
                        Actor:          &actor,
2✔
108
                        UseCaseSupport: []UseCaseSupportType{useCaseSupport},
2✔
109
                }
2✔
110
                n.UseCaseInformation = append(n.UseCaseInformation, useCaseInformation)
2✔
111
        }
2✔
112
}
113

114
func (n *NodeManagementUseCaseDataType) HasUseCaseSupport(
115
        address FeatureAddressType,
116
        actor UseCaseActorType,
117
        useCaseName UseCaseNameType) bool {
2✔
118
        nmMux.Lock()
2✔
119
        defer nmMux.Unlock()
2✔
120

2✔
121
        // is there an entry for the entity address, actor and usecase name
2✔
122
        _, ok := n.useCaseInformationIndex(address, actor, useCaseName)
2✔
123
        return ok
2✔
124
}
2✔
125

126
// Set the availability of a usecase
127
func (n *NodeManagementUseCaseDataType) SetAvailability(
128
        address FeatureAddressType,
129
        actor UseCaseActorType,
130
        useCaseName UseCaseNameType,
131
        availability bool,
132
) {
2✔
133
        nmMux.Lock()
2✔
134
        defer nmMux.Unlock()
2✔
135

2✔
136
        // is there an entry for the entity address, actor and usecase name
2✔
137
        usecaseIndex, ok := n.useCaseInformationIndex(address, actor, useCaseName)
2✔
138
        if !ok {
3✔
139
                return
1✔
140
        }
1✔
141

142
        useCaseInformation := n.UseCaseInformation[usecaseIndex]
1✔
143
        for index, item := range useCaseInformation.UseCaseSupport {
2✔
144
                if item.UseCaseName != nil && *item.UseCaseName == useCaseName {
2✔
145
                        n.UseCaseInformation[usecaseIndex].UseCaseSupport[index].UseCaseAvailable = util.Ptr(availability)
1✔
146

1✔
147
                        return
1✔
148
                }
1✔
149
        }
150
}
151

152
// Remove a UseCaseSupportType with
153
// a provided FeatureAddressType, UseCaseActorType and UseCaseNameType
154
func (n *NodeManagementUseCaseDataType) RemoveUseCaseSupport(
155
        address FeatureAddressType,
156
        actor UseCaseActorType,
157
        useCaseName UseCaseNameType,
158
) {
5✔
159
        nmMux.Lock()
5✔
160
        defer nmMux.Unlock()
5✔
161

5✔
162
        // is there an entry for the entity address, actor and usecase name
5✔
163
        usecaseIndex, ok := n.useCaseInformationIndex(address, actor, useCaseName)
5✔
164
        if !ok {
7✔
165
                return
2✔
166
        }
2✔
167

168
        var usecaseInfo []UseCaseInformationDataType
3✔
169

3✔
170
        for index, item := range n.UseCaseInformation {
8✔
171
                if index != usecaseIndex {
7✔
172
                        usecaseInfo = append(usecaseInfo, item)
2✔
173
                        continue
2✔
174
                }
175

176
                item.Remove(useCaseName)
3✔
177

3✔
178
                // only add the item if there are any usecases left
3✔
179
                if len(item.UseCaseSupport) == 0 {
4✔
180
                        continue
1✔
181
                }
182

183
                usecaseInfo = append(usecaseInfo, item)
2✔
184
        }
185

186
        n.UseCaseInformation = usecaseInfo
3✔
187
}
188

189
// Remove all data for a given address type
190
func (n *NodeManagementUseCaseDataType) RemoveUseCaseDataForAddress(address FeatureAddressType) {
1✔
191
        nmMux.Lock()
1✔
192
        defer nmMux.Unlock()
1✔
193

1✔
194
        var usecaseInfo []UseCaseInformationDataType
1✔
195

1✔
196
        for _, item := range n.UseCaseInformation {
2✔
197
                if !reflect.DeepEqual(item.Address, &address) {
1✔
198
                        usecaseInfo = append(usecaseInfo, item)
×
199
                        continue
×
200
                }
201
        }
202

203
        n.UseCaseInformation = usecaseInfo
1✔
204
}
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