Skip to content

Commit 3529707

Browse files
vky5dmathieucodeboten
authored
docs: add testable examples for component.ID and component.Type Closes Issue #13146 (#13430)
#### Description Adds testable examples for `component.ID` and `component.Type` to improve the documentation rendered on [pkg.go.dev](https://pkg.go.dev/go.opentelemetry.io/collector/component). These examples demonstrate how to construct and use these types in a simple and idiomatic way, per the Go documentation guidelines. #### Link to tracking issue Fixes #13146 #### Testing Testable examples were added in `component/identifiable_example_test.go` and verified using: ``` cd component/ go test ./... -v ``` --------- Co-authored-by: Damien Mathieu <42@dmathieu.com> Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
1 parent cd7fbdb commit 3529707

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package component_test
5+
6+
import (
7+
"fmt"
8+
9+
"go.opentelemetry.io/collector/component"
10+
)
11+
12+
func ExampleNewType() {
13+
t, err := component.NewType("exampleexporter")
14+
if err != nil {
15+
fmt.Println("error:", err)
16+
return
17+
}
18+
fmt.Println(t.String())
19+
20+
// Output:
21+
// exampleexporter
22+
}
23+
24+
func ExampleMustNewType() {
25+
t := component.MustNewType("examplereceiver")
26+
fmt.Println(t.String())
27+
28+
// Output:
29+
// examplereceiver
30+
}
31+
32+
func ExampleNewID() {
33+
t := component.MustNewType("exampleprocessor")
34+
id := component.NewID(t)
35+
fmt.Println(id.String())
36+
37+
// Output:
38+
// exampleprocessor
39+
}
40+
41+
func ExampleMustNewID() {
42+
id := component.MustNewID("examplereceiver")
43+
fmt.Println(id.String())
44+
45+
// Output:
46+
// examplereceiver
47+
}
48+
49+
func ExampleNewIDWithName() {
50+
t := component.MustNewType("exampleexporter")
51+
id := component.NewIDWithName(t, "customname")
52+
fmt.Println(id.String())
53+
54+
// Output:
55+
// exampleexporter/customname
56+
}
57+
58+
func ExampleMustNewIDWithName() {
59+
id := component.MustNewIDWithName("exampleprocessor", "customproc")
60+
fmt.Println(id.String())
61+
62+
// Output:
63+
// exampleprocessor/customproc
64+
}

0 commit comments

Comments
 (0)