forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distribution_metadata_test.go
113 lines (99 loc) · 3.01 KB
/
distribution_metadata_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
)
func TestComponentsArePresent(t *testing.T) {
components, err := components()
require.NoError(t, err)
var metadataComponents []string
e := filepath.Walk(filepath.Join("..", ".."), func(path string, info os.FileInfo, err error) error {
if err == nil && "metadata.yaml" == info.Name() {
metadataComponents = append(metadataComponents, path)
}
return nil
})
require.NoError(t, e)
for _, metadataComponent := range metadataComponents {
t.Run(metadataComponent, func(tt *testing.T) {
m, err := loadMetadata(metadataComponent)
require.NoError(tt, err)
if m.Status == nil {
tt.Skip("no status present, skipping", metadataComponent)
return
}
inDevelopment := len(m.Status.Stability) == 0
deprecated := false
inUse := false
for stability, pipelines := range m.Status.Stability {
if len(pipelines) > 0 {
switch stability {
case "development":
inDevelopment = true
case "deprecated":
deprecated = true
case "unmaintained":
// consider not in use.
default: // alpha, beta, stable
inUse = true
}
}
}
if inDevelopment && !inUse {
tt.Skip("component in development, skipping", metadataComponent)
return
}
if deprecated && !inUse {
tt.Skip("component deprecated, skipping", metadataComponent)
return
}
cType := component.MustNewType(m.Type)
switch m.Status.Class {
case "connector":
assert.NotNil(tt, components.Connectors[cType], "missing connector: %s", m.Type)
case "exporter":
assert.NotNil(tt, components.Exporters[cType], "missing exporter: %s", m.Type)
case "extension":
assert.NotNil(tt, components.Extensions[cType], "missing extension: %s", m.Type)
case "processor":
assert.NotNil(tt, components.Processors[cType], "missing processor: %s", m.Type)
case "receiver":
assert.NotNil(tt, components.Receivers[cType], "missing receiver: %s", m.Type)
}
})
}
}
func loadMetadata(filePath string) (metadata, error) {
cp, err := fileprovider.New().Retrieve(context.Background(), "file:"+filePath, nil)
if err != nil {
return metadata{}, err
}
conf, err := cp.AsConf()
if err != nil {
return metadata{}, err
}
md := metadata{}
if err := conf.Unmarshal(&md, confmap.WithIgnoreUnused()); err != nil {
return md, err
}
return md, nil
}
type metadata struct {
Type string `mapstructure:"type"`
Status *status `mapstructure:"status"`
}
type status struct {
Stability map[string][]string `mapstructure:"stability"`
Distributions []string `mapstructure:"distributions"`
Class string `mapstructure:"class"`
Warnings []string `mapstructure:"warnings"`
}