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

sapslaj / mid / 31137380617

07 Aug 2026 01:14AM UTC coverage: 41.734% (-24.8%) from 66.574%
31137380617

push

github

sapslaj
fix: agent was getting re-installed every time

this _should_ help with that i hope

7 of 15 new or added lines in 1 file covered. (46.67%)

3299 existing lines in 30 files now uncovered.

5440 of 13035 relevant lines covered (41.73%)

211.19 hits per line

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

92.08
/pkg/pdiff/pdiff.go
1
package pdiff
2

3
import (
4
        "maps"
5
        "reflect"
6
        "slices"
7

8
        "github.com/pulumi/pulumi/sdk/v3/go/common/resource"
9
        "github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
10
        "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
11

12
        p "github.com/sapslaj/mid/pkg/providerfw"
13
        "github.com/sapslaj/mid/pkg/providerfw/ende"
14
        "github.com/sapslaj/mid/pkg/providerfw/introspect"
15
)
16

17
// DiffAttributes performs deep equality on two structs only for the attributes
18
// provided and returns a DiffResponse
19
func DiffAttributes(inputs any, state any, attributes []string) p.DiffResponse {
18✔
20
        inputProps, err := introspect.FindProperties(reflect.TypeOf(inputs))
18✔
21
        contract.AssertNoErrorf(err, "could not get properties")
18✔
22

18✔
23
        encoder := &ende.Encoder{}
18✔
24

18✔
25
        inputsMap, err := encoder.Encode(inputs)
18✔
26
        contract.AssertNoErrorf(err, "could not diff inputs")
18✔
27

18✔
28
        stateMap, err := encoder.Encode(state)
18✔
29
        contract.AssertNoErrorf(err, "could not diff state")
18✔
30

18✔
31
        // Olds is an Output, but news is an Input. Output should be a superset of
18✔
32
        // Input, so we need to filter out fields that are in Output but not Input.
18✔
33
        oldInputsMap := resource.PropertyMap{}
18✔
34
        for k := range inputsMap {
77✔
35
                oldInputsMap[k] = stateMap[k]
59✔
36
        }
59✔
37

38
        objDiff := oldInputsMap.Diff(inputsMap)
18✔
39
        pluginDiff := plugin.NewDetailedDiffFromObjectDiff(objDiff, true)
18✔
40
        diff := map[string]p.PropertyDiff{}
18✔
41

18✔
42
        for k, v := range pluginDiff {
44✔
43
                propertyPath, err := resource.ParsePropertyPath(k)
26✔
44
                contract.AssertNoErrorf(err, "could not parse generated property path")
26✔
45

26✔
46
                selected := false
26✔
47
                for i := range attributes {
330✔
48
                        attributePropertyPath, err := resource.ParsePropertyPath(attributes[i])
304✔
49
                        contract.AssertNoErrorf(err, "could not parse attribute property path")
304✔
50

304✔
51
                        if attributePropertyPath.Contains(propertyPath) {
319✔
52
                                selected = true
15✔
53
                        }
15✔
54
                }
55
                if !selected {
37✔
56
                        continue
11✔
57
                }
58

59
                set := func(kind p.DiffKind) {
30✔
60
                        diff[k] = p.PropertyDiff{
15✔
61
                                Kind:      kind,
15✔
62
                                InputDiff: v.InputDiff,
15✔
63
                        }
15✔
64
                }
15✔
65

66
                fieldTag := inputProps[k]
15✔
67
                if fieldTag.ReplaceOnChanges {
18✔
68
                        v.Kind = v.Kind.AsReplace()
3✔
69
                }
3✔
70

71
                switch v.Kind {
15✔
UNCOV
72
                case plugin.DiffAdd:
×
UNCOV
73
                        set(p.Add)
×
74
                case plugin.DiffAddReplace:
×
75
                        set(p.AddReplace)
×
UNCOV
76
                case plugin.DiffDelete:
×
UNCOV
77
                        set(p.Delete)
×
78
                case plugin.DiffDeleteReplace:
×
79
                        set(p.DeleteReplace)
×
80
                case plugin.DiffUpdate:
12✔
81
                        set(p.Update)
12✔
82
                case plugin.DiffUpdateReplace:
3✔
83
                        set(p.UpdateReplace)
3✔
84
                }
85
        }
86
        return p.DiffResponse{
18✔
87
                HasChanges:   len(diff) > 0,
18✔
88
                DetailedDiff: diff,
18✔
89
        }
18✔
90
}
91

92
// DiffAllAttributesExcept performs a deep equality on two structs for all
93
// attributes except the list provided and returns a diff response.
94
func DiffAllAttributesExcept(inputs any, state any, exceptAttributes []string) p.DiffResponse {
12✔
95
        inputProps, err := introspect.FindProperties(reflect.TypeOf(inputs))
12✔
96
        contract.AssertNoErrorf(err, "could not get properties")
12✔
97

12✔
98
        attributes := []string{}
12✔
99
        for prop := range inputProps {
209✔
100
                if !slices.Contains(exceptAttributes, prop) {
385✔
101
                        attributes = append(attributes, prop)
188✔
102
                }
188✔
103
        }
104

105
        return DiffAttributes(inputs, state, attributes)
12✔
106
}
107

108
// DiffAllAttributes performs a deep equality on two structs for all attributes
109
func DiffAllAttributes(inputs any, state any) p.DiffResponse {
6✔
110
        return DiffAllAttributesExcept(inputs, state, []string{})
6✔
111
}
6✔
112

113
// ForceDiffReplace changes all of the properties in the DiffResponse to be the
114
// "-replace" equivalent to trigger a resource replacement.
115
func ForceDiffReplace(diff p.DiffResponse) p.DiffResponse {
1✔
116
        for key, propdiff := range diff.DetailedDiff {
8✔
117
                switch propdiff.Kind {
7✔
118
                case p.Add:
1✔
119
                        propdiff.Kind = p.AddReplace
1✔
120
                case p.Delete:
1✔
121
                        propdiff.Kind = p.DeleteReplace
1✔
122
                case p.Update:
1✔
123
                        propdiff.Kind = p.UpdateReplace
1✔
124
                }
125
                diff.DetailedDiff[key] = propdiff
7✔
126
        }
127
        return diff
1✔
128
}
129

130
// MergeDiffResponses will merge an arbitrary number of DiffResponses together
131
// with the last taking the highest precedence. Any DiffResponse that has
132
// `HasChanges` or `DeleteBeforeReplace` set will result in the returned
133
// DiffResponse to have those set as well.
134
func MergeDiffResponses(drs ...p.DiffResponse) p.DiffResponse {
3✔
135
        diff := p.DiffResponse{
3✔
136
                HasChanges:   false,
3✔
137
                DetailedDiff: map[string]p.PropertyDiff{},
3✔
138
        }
3✔
139
        for _, dr := range drs {
13✔
140
                if dr.HasChanges {
15✔
141
                        diff.HasChanges = true
5✔
142
                }
5✔
143
                if dr.DeleteBeforeReplace {
11✔
144
                        diff.DeleteBeforeReplace = true
1✔
145
                }
1✔
146
                maps.Copy(diff.DetailedDiff, dr.DetailedDiff)
10✔
147
        }
148
        return diff
3✔
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc