Skip to content

Commit b302feb

Browse files
authored
[chore] Re-write the internal.State in pdata to support multiple properties. (open-telemetry#13633)
Part of open-telemetry#13631 Signed-off-by: Bogdan Drutu <[email protected]>
1 parent eb9588b commit b302feb

File tree

231 files changed

+996
-922
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+996
-922
lines changed

internal/cmd/pdatagen/internal/one_of_message_value.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ const oneOfMessageAccessorsTestTemplate = `func Test{{ .structName }}_{{ .fieldN
4141
internal.FillOrigTest{{ .returnType }}(ms.orig.Get{{ .originOneOfFieldName }}().(*{{ .originStructType }}).{{ .fieldName }})
4242
assert.Equal(t, {{ .typeName }}, ms.{{ .originOneOfTypeFuncName }}())
4343
assert.Equal(t, generateTest{{ .returnType }}(), ms.{{ .fieldName }}())
44-
sharedState := internal.StateReadOnly
45-
assert.Panics(t, func() { new{{ .structName }}(&{{ .originStructName }}{}, &sharedState).SetEmpty{{ .fieldName }}() })
44+
sharedState := internal.NewState()
45+
sharedState.MarkReadOnly()
46+
assert.Panics(t, func() { new{{ .structName }}(&{{ .originStructName }}{}, sharedState).SetEmpty{{ .fieldName }}() })
4647
}
4748
`
4849

internal/cmd/pdatagen/internal/one_of_primitive_value.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ const oneOfPrimitiveAccessorTestTemplate = `func Test{{ .structName }}_{{ .acces
3939
assert.Equal(t, {{ .testValue }}, ms.{{ .accessorFieldName }}())
4040
{{- end }}
4141
assert.Equal(t, {{ .typeName }}, ms.{{ .originOneOfTypeFuncName }}())
42-
sharedState := internal.StateReadOnly
43-
assert.Panics(t, func() { new{{ .structName }}(&{{ .originStructName }}{}, &sharedState).Set{{ .accessorFieldName }}({{ .testValue }}) })
42+
sharedState := internal.NewState()
43+
sharedState.MarkReadOnly()
44+
assert.Panics(t, func() { new{{ .structName }}(&{{ .originStructName }}{}, sharedState).Set{{ .accessorFieldName }}({{ .testValue }}) })
4445
}
4546
`
4647

internal/cmd/pdatagen/internal/primitive_field.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ const primitiveAccessorsTestTemplate = `func Test{{ .structName }}_{{ .fieldName
4040
{{- else }}
4141
assert.Equal(t, {{ .testValue }}, ms.{{ .fieldName }}())
4242
{{- end }}
43-
sharedState := internal.StateReadOnly
44-
assert.Panics(t, func() { new{{ .structName }}(&{{ .originStructName }}{}, &sharedState).Set{{ .fieldName }}({{ .testValue }}) })
43+
sharedState := internal.NewState()
44+
sharedState.MarkReadOnly()
45+
assert.Panics(t, func() { new{{ .structName }}(&{{ .originStructName }}{}, sharedState).Set{{ .fieldName }}({{ .testValue }}) })
4546
}`
4647

4748
const primitiveSetTestTemplate = `orig.{{ .originFieldName }} = {{ .testValue }}`

internal/cmd/pdatagen/internal/templates/message.go.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func new{{ .structName }}(orig *{{ .originFullName }}, state *internal.State) {{
4141
// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice,
4242
// OR directly access the member if this is embedded in another struct.
4343
func New{{ .structName }}() {{ .structName }} {
44-
state := internal.StateMutable
45-
return new{{ .structName }}(&{{ .originFullName }}{}, &state)
44+
return new{{ .structName }}(&{{ .originFullName }}{}, internal.NewState())
4645
}
4746

4847
// MoveTo moves all properties from the current struct overriding the destination and

internal/cmd/pdatagen/internal/templates/message_internal.go.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ func New{{ .structName }}(orig *{{ .originFullName }}, state *State) {{ .structN
3333
func GenerateTest{{ .structName }}() {{ .structName }} {
3434
orig := {{ .originFullName }}{}
3535
FillOrigTest{{ .originName }}(&orig)
36-
state := StateMutable
37-
return New{{ .structName }}(&orig, &state)
36+
return New{{ .structName }}(&orig, NewState())
3837
}
3938

4039
{{ end }}

internal/cmd/pdatagen/internal/templates/message_test.go.tmpl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ func Test{{ .structName }}_MoveTo(t *testing.T) {
2020
assert.Equal(t, generateTest{{ .structName }}(), dest)
2121
dest.MoveTo(dest)
2222
assert.Equal(t, generateTest{{ .structName }}(), dest)
23-
sharedState := internal.StateReadOnly
24-
assert.Panics(t, func() { ms.MoveTo(new{{ .structName }}(&{{ .originFullName }}{}, &sharedState)) })
25-
assert.Panics(t, func() { new{{ .structName }}(&{{ .originFullName }}{}, &sharedState).MoveTo(dest) })
23+
sharedState := internal.NewState()
24+
sharedState.MarkReadOnly()
25+
assert.Panics(t, func() { ms.MoveTo(new{{ .structName }}(&{{ .originFullName }}{}, sharedState)) })
26+
assert.Panics(t, func() { new{{ .structName }}(&{{ .originFullName }}{}, sharedState).MoveTo(dest) })
2627
}
2728

2829
func Test{{ .structName }}_CopyTo(t *testing.T) {
@@ -33,8 +34,9 @@ func Test{{ .structName }}_CopyTo(t *testing.T) {
3334
orig = generateTest{{ .structName }}()
3435
orig.CopyTo(ms)
3536
assert.Equal(t, orig, ms)
36-
sharedState := internal.StateReadOnly
37-
assert.Panics(t, func() { ms.CopyTo(new{{ .structName }}(&{{ .originFullName }}{}, &sharedState)) })
37+
sharedState := internal.NewState()
38+
sharedState.MarkReadOnly()
39+
assert.Panics(t, func() { ms.CopyTo(new{{ .structName }}(&{{ .originFullName }}{}, sharedState)) })
3840
}
3941

4042
{{ range .fields }}

internal/cmd/pdatagen/internal/templates/primitive_slice.go.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ func (ms {{ .structName }}) getState() *internal.State {
3030
// New{{ .structName }} creates a new empty {{ .structName }}.
3131
func New{{ .structName }}() {{ .structName }} {
3232
orig := []{{ .itemType }}(nil)
33-
state := internal.StateMutable
34-
return {{ .structName }}(internal.New{{ .structName }}(&orig, &state))
33+
return {{ .structName }}(internal.New{{ .structName }}(&orig, internal.NewState()))
3534
}
3635

3736
// AsRaw returns a copy of the []{{ .itemType }} slice.

internal/cmd/pdatagen/internal/templates/primitive_slice_internal.go.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ func New{{ .structName }}(orig *[]{{ .itemType }}, state *State) {{ .structName
3131

3232
func GenerateTest{{ .structName }}() {{ .structName }} {
3333
orig := GenerateOrigTest{{ .elementOriginName }}Slice()
34-
state := StateMutable
35-
return New{{ .structName }}(&orig, &state)
34+
return New{{ .structName }}(&orig, NewState())
3635
}
3736

3837
func CopyOrig{{ .elementOriginName }}Slice(dst, src []{{ .itemType }}) []{{ .itemType }} {

internal/cmd/pdatagen/internal/templates/primitive_slice_test.go.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ func TestNew{{ .structName }}(t *testing.T) {
7676

7777
func Test{{ .structName }}ReadOnly(t *testing.T) {
7878
raw := []{{ .itemType }}{ {{ .testOrigVal }}}
79-
state := internal.StateReadOnly
80-
ms := {{ .structName }}(internal.New{{ .structName }}(&raw, &state))
79+
sharedState := internal.NewState()
80+
sharedState.MarkReadOnly()
81+
ms := {{ .structName }}(internal.New{{ .structName }}(&raw, sharedState))
8182

8283
assert.Equal(t, 3, ms.Len())
8384
{{- if eq .itemType "float64" }}

internal/cmd/pdatagen/internal/templates/slice.go.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ func new{{ .structName }}(orig *[]{{ .originElementType }}, state *internal.Stat
4040
// Can use "EnsureCapacity" to initialize with a given capacity.
4141
func New{{ .structName }}() {{ .structName }} {
4242
orig := []{{ .originElementType }}(nil)
43-
state := internal.StateMutable
44-
return new{{ .structName }}(&orig, &state)
43+
return new{{ .structName }}(&orig, internal.NewState())
4544
}
4645

4746
// Len returns the number of elements in the slice.

0 commit comments

Comments
 (0)