[chore]: enable gofumpt linter in client, cmd, component, config and confmap (#11587)
#### Description [gofumpt](https://golangci-lint.run/usage/linters/#gofumpt) is a stricter format than gofmt, while being backwards compatible. Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
28d93fa69d
commit
808fb7c260
|
|
@ -77,6 +77,7 @@ func (e *exampleAuthData) GetAttribute(key string) any {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *exampleAuthData) GetAttributeNames() []string {
|
||||
return []string{"username"}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const defaultBetaOtelColVersion = "v0.115.0"
|
||||
const defaultStableOtelColVersion = "v1.21.0"
|
||||
|
||||
var (
|
||||
// errMissingGoMod indicates an empty gomod field
|
||||
errMissingGoMod = errors.New("missing gomod specification for module")
|
||||
const (
|
||||
defaultBetaOtelColVersion = "v0.115.0"
|
||||
defaultStableOtelColVersion = "v1.21.0"
|
||||
)
|
||||
|
||||
// errMissingGoMod indicates an empty gomod field
|
||||
var errMissingGoMod = errors.New("missing gomod specification for module")
|
||||
|
||||
// Config holds the builder's configuration
|
||||
type Config struct {
|
||||
Logger *zap.Logger
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ func Generate(cfg *Config) error {
|
|||
|
||||
// if the file does not exist, try to create it
|
||||
if _, err := os.Stat(cfg.Distribution.OutputPath); os.IsNotExist(err) {
|
||||
if err = os.Mkdir(cfg.Distribution.OutputPath, 0750); err != nil {
|
||||
if err = os.Mkdir(cfg.Distribution.OutputPath, 0o750); err != nil {
|
||||
return fmt.Errorf("failed to create output path: %w", err)
|
||||
}
|
||||
} else if err != nil {
|
||||
|
|
@ -109,7 +109,7 @@ func Compile(cfg *Config) error {
|
|||
|
||||
cfg.Logger.Info("Compiling")
|
||||
|
||||
var ldflags = "-s -w"
|
||||
ldflags := "-s -w"
|
||||
|
||||
args := []string{"build", "-trimpath", "-o", cfg.Distribution.Name}
|
||||
if cfg.Distribution.DebugCompilation {
|
||||
|
|
|
|||
|
|
@ -37,77 +37,75 @@ require (
|
|||
modulePrefix = "go.opentelemetry.io/collector"
|
||||
)
|
||||
|
||||
var (
|
||||
replaceModules = []string{
|
||||
"",
|
||||
"/component",
|
||||
"/component/componenttest",
|
||||
"/component/componentstatus",
|
||||
"/client",
|
||||
"/config/configauth",
|
||||
"/config/configcompression",
|
||||
"/config/configgrpc",
|
||||
"/config/confighttp",
|
||||
"/config/confignet",
|
||||
"/config/configopaque",
|
||||
"/config/configretry",
|
||||
"/config/configtelemetry",
|
||||
"/config/configtls",
|
||||
"/config/internal",
|
||||
"/confmap",
|
||||
"/confmap/provider/envprovider",
|
||||
"/confmap/provider/fileprovider",
|
||||
"/confmap/provider/httpprovider",
|
||||
"/confmap/provider/httpsprovider",
|
||||
"/confmap/provider/yamlprovider",
|
||||
"/consumer",
|
||||
"/consumer/consumererror",
|
||||
"/consumer/consumererror/consumererrorprofiles",
|
||||
"/consumer/consumerprofiles",
|
||||
"/consumer/consumertest",
|
||||
"/connector",
|
||||
"/connector/connectortest",
|
||||
"/connector/connectorprofiles",
|
||||
"/exporter",
|
||||
"/exporter/debugexporter",
|
||||
"/exporter/exporterprofiles",
|
||||
"/exporter/exportertest",
|
||||
"/exporter/exporterhelper/exporterhelperprofiles",
|
||||
"/exporter/nopexporter",
|
||||
"/exporter/otlpexporter",
|
||||
"/exporter/otlphttpexporter",
|
||||
"/extension",
|
||||
"/extension/auth",
|
||||
"/extension/auth/authtest",
|
||||
"/extension/experimental/storage",
|
||||
"/extension/extensioncapabilities",
|
||||
"/extension/extensiontest",
|
||||
"/extension/zpagesextension",
|
||||
"/featuregate",
|
||||
"/internal/memorylimiter",
|
||||
"/internal/fanoutconsumer",
|
||||
"/internal/sharedcomponent",
|
||||
"/otelcol",
|
||||
"/pipeline",
|
||||
"/pipeline/pipelineprofiles",
|
||||
"/processor",
|
||||
"/processor/processortest",
|
||||
"/processor/batchprocessor",
|
||||
"/processor/memorylimiterprocessor",
|
||||
"/processor/processorprofiles",
|
||||
"/receiver",
|
||||
"/receiver/nopreceiver",
|
||||
"/receiver/otlpreceiver",
|
||||
"/receiver/receiverprofiles",
|
||||
"/receiver/receivertest",
|
||||
"/pdata",
|
||||
"/pdata/testdata",
|
||||
"/pdata/pprofile",
|
||||
"/scraper",
|
||||
"/semconv",
|
||||
"/service",
|
||||
}
|
||||
)
|
||||
var replaceModules = []string{
|
||||
"",
|
||||
"/component",
|
||||
"/component/componenttest",
|
||||
"/component/componentstatus",
|
||||
"/client",
|
||||
"/config/configauth",
|
||||
"/config/configcompression",
|
||||
"/config/configgrpc",
|
||||
"/config/confighttp",
|
||||
"/config/confignet",
|
||||
"/config/configopaque",
|
||||
"/config/configretry",
|
||||
"/config/configtelemetry",
|
||||
"/config/configtls",
|
||||
"/config/internal",
|
||||
"/confmap",
|
||||
"/confmap/provider/envprovider",
|
||||
"/confmap/provider/fileprovider",
|
||||
"/confmap/provider/httpprovider",
|
||||
"/confmap/provider/httpsprovider",
|
||||
"/confmap/provider/yamlprovider",
|
||||
"/consumer",
|
||||
"/consumer/consumererror",
|
||||
"/consumer/consumererror/consumererrorprofiles",
|
||||
"/consumer/consumerprofiles",
|
||||
"/consumer/consumertest",
|
||||
"/connector",
|
||||
"/connector/connectortest",
|
||||
"/connector/connectorprofiles",
|
||||
"/exporter",
|
||||
"/exporter/debugexporter",
|
||||
"/exporter/exporterprofiles",
|
||||
"/exporter/exportertest",
|
||||
"/exporter/exporterhelper/exporterhelperprofiles",
|
||||
"/exporter/nopexporter",
|
||||
"/exporter/otlpexporter",
|
||||
"/exporter/otlphttpexporter",
|
||||
"/extension",
|
||||
"/extension/auth",
|
||||
"/extension/auth/authtest",
|
||||
"/extension/experimental/storage",
|
||||
"/extension/extensioncapabilities",
|
||||
"/extension/extensiontest",
|
||||
"/extension/zpagesextension",
|
||||
"/featuregate",
|
||||
"/internal/memorylimiter",
|
||||
"/internal/fanoutconsumer",
|
||||
"/internal/sharedcomponent",
|
||||
"/otelcol",
|
||||
"/pipeline",
|
||||
"/pipeline/pipelineprofiles",
|
||||
"/processor",
|
||||
"/processor/processortest",
|
||||
"/processor/batchprocessor",
|
||||
"/processor/memorylimiterprocessor",
|
||||
"/processor/processorprofiles",
|
||||
"/receiver",
|
||||
"/receiver/nopreceiver",
|
||||
"/receiver/otlpreceiver",
|
||||
"/receiver/receiverprofiles",
|
||||
"/receiver/receivertest",
|
||||
"/pdata",
|
||||
"/pdata/testdata",
|
||||
"/pdata/pprofile",
|
||||
"/scraper",
|
||||
"/semconv",
|
||||
"/service",
|
||||
}
|
||||
|
||||
func newTestConfig(t testing.TB) *Config {
|
||||
cfg, err := NewDefaultConfig()
|
||||
|
|
@ -429,14 +427,14 @@ func verifyGoMod(t *testing.T, dir string, replaceMods map[string]bool) {
|
|||
func makeModule(dir string, fileContents []byte) error {
|
||||
// if the file does not exist, try to create it
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
if err = os.Mkdir(dir, 0750); err != nil {
|
||||
if err = os.Mkdir(dir, 0o750); err != nil {
|
||||
return fmt.Errorf("failed to create output path: %w", err)
|
||||
}
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("failed to create output path: %w", err)
|
||||
}
|
||||
|
||||
err := os.WriteFile(filepath.Clean(filepath.Join(dir, "go.mod")), fileContents, 0600)
|
||||
err := os.WriteFile(filepath.Clean(filepath.Join(dir, "go.mod")), fileContents, 0o600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to write go.mod file: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
version = ""
|
||||
)
|
||||
var version = ""
|
||||
|
||||
func init() {
|
||||
// the second returned value is a boolean, which is true if the binaries are built with module support.
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func run(ymlPath string) error {
|
|||
tmplDir := "templates"
|
||||
|
||||
codeDir := filepath.Join(ymlDir, "internal", md.GeneratedPackageName)
|
||||
if err = os.MkdirAll(codeDir, 0700); err != nil {
|
||||
if err = os.MkdirAll(codeDir, 0o700); err != nil {
|
||||
return fmt.Errorf("unable to create output directory %q: %w", codeDir, err)
|
||||
}
|
||||
if md.Status != nil {
|
||||
|
|
@ -130,7 +130,7 @@ func run(ymlPath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if err = os.MkdirAll(filepath.Join(codeDir, "testdata"), 0700); err != nil {
|
||||
if err = os.MkdirAll(filepath.Join(codeDir, "testdata"), 0o700); err != nil {
|
||||
return fmt.Errorf("unable to create output directory %q: %w", filepath.Join(codeDir, "testdata"), err)
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +376,7 @@ func inlineReplace(tmplFile string, outputFile string, md Metadata, start string
|
|||
return err
|
||||
}
|
||||
|
||||
var re = regexp.MustCompile(fmt.Sprintf("%s[\\s\\S]*%s", start, end))
|
||||
re := regexp.MustCompile(fmt.Sprintf("%s[\\s\\S]*%s", start, end))
|
||||
if !re.Match(readmeContents) {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -391,7 +391,7 @@ func inlineReplace(tmplFile string, outputFile string, md Metadata, start string
|
|||
}
|
||||
|
||||
s := re.ReplaceAllString(string(readmeContents), string(buf))
|
||||
if err := os.WriteFile(outputFile, []byte(s), 0600); err != nil {
|
||||
if err := os.WriteFile(outputFile, []byte(s), 0o600); err != nil {
|
||||
return fmt.Errorf("failed writing %q: %w", outputFile, err)
|
||||
}
|
||||
|
||||
|
|
@ -416,7 +416,7 @@ func generateFile(tmplFile string, outputFile string, md Metadata, goPackage str
|
|||
}
|
||||
}
|
||||
|
||||
if err := os.WriteFile(outputFile, result, 0600); err != nil {
|
||||
if err := os.WriteFile(outputFile, result, 0o600); err != nil {
|
||||
return fmt.Errorf("failed writing %q: %w", outputFile, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,16 +137,16 @@ func TestRunContents(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.yml, func(t *testing.T) {
|
||||
tmpdir := filepath.Join(t.TempDir(), "shortname")
|
||||
err := os.MkdirAll(tmpdir, 0750)
|
||||
err := os.MkdirAll(tmpdir, 0o750)
|
||||
require.NoError(t, err)
|
||||
ymlContent, err := os.ReadFile(filepath.Join("testdata", tt.yml))
|
||||
require.NoError(t, err)
|
||||
metadataFile := filepath.Join(tmpdir, "metadata.yaml")
|
||||
require.NoError(t, os.WriteFile(metadataFile, ymlContent, 0600))
|
||||
require.NoError(t, os.WriteFile(metadataFile, ymlContent, 0o600))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(tmpdir, "README.md"), []byte(`
|
||||
<!-- status autogenerated section -->
|
||||
foo
|
||||
<!-- end autogenerated section -->`), 0600))
|
||||
<!-- end autogenerated section -->`), 0o600))
|
||||
|
||||
err = run(metadataFile)
|
||||
if tt.wantErr {
|
||||
|
|
@ -472,7 +472,7 @@ Some info about a component
|
|||
tmpdir := t.TempDir()
|
||||
|
||||
readmeFile := filepath.Join(tmpdir, "README.md")
|
||||
require.NoError(t, os.WriteFile(readmeFile, []byte(tt.markdown), 0600))
|
||||
require.NoError(t, os.WriteFile(readmeFile, []byte(tt.markdown), 0o600))
|
||||
|
||||
err := inlineReplace("templates/readme.md.tmpl", readmeFile, md, statusStart, statusEnd, "metadata")
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestFormatIdentifier(t *testing.T) {
|
||||
var tests = []struct {
|
||||
tests := []struct {
|
||||
input string
|
||||
want string
|
||||
exported bool
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ func (m *Metric) Unmarshal(parser *confmap.Conf) error {
|
|||
}
|
||||
return parser.Unmarshal(m)
|
||||
}
|
||||
|
||||
func (m Metric) Data() MetricData {
|
||||
if m.Sum != nil {
|
||||
return m.Sum
|
||||
|
|
|
|||
|
|
@ -105,8 +105,10 @@ func Test_ReportStatus(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
var _ = (component.Host)(nil)
|
||||
var _ = (Reporter)(nil)
|
||||
var (
|
||||
_ = (component.Host)(nil)
|
||||
_ = (Reporter)(nil)
|
||||
)
|
||||
|
||||
type reporter struct {
|
||||
reportStatusCalled bool
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func newErrMapType() *errMapType {
|
|||
}
|
||||
|
||||
func TestValidateConfig(t *testing.T) {
|
||||
var tests = []struct {
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg any
|
||||
expected error
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ func TestMarshalText(t *testing.T) {
|
|||
|
||||
func TestUnmarshalText(t *testing.T) {
|
||||
validType := MustNewType("valid_type")
|
||||
var testCases = []struct {
|
||||
testCases := []struct {
|
||||
name string
|
||||
expectedErr bool
|
||||
expectedID ID
|
||||
|
|
|
|||
|
|
@ -124,45 +124,54 @@ func setupTestPayloads() []testPayload {
|
|||
payloads = append(payloads, testPayload{
|
||||
name: "sm_log_request",
|
||||
message: testdata.GenerateLogs(1),
|
||||
marshaler: logMarshaler})
|
||||
marshaler: logMarshaler,
|
||||
})
|
||||
payloads = append(payloads, testPayload{
|
||||
name: "md_log_request",
|
||||
message: testdata.GenerateLogs(2),
|
||||
marshaler: logMarshaler})
|
||||
marshaler: logMarshaler,
|
||||
})
|
||||
payloads = append(payloads, testPayload{
|
||||
name: "lg_log_request",
|
||||
message: testdata.GenerateLogs(50),
|
||||
marshaler: logMarshaler})
|
||||
marshaler: logMarshaler,
|
||||
})
|
||||
|
||||
// trace payloads
|
||||
tracesMarshaler := &traceMarshaler{Marshaler: &ptrace.ProtoMarshaler{}}
|
||||
payloads = append(payloads, testPayload{
|
||||
name: "sm_trace_request",
|
||||
message: testdata.GenerateTraces(1),
|
||||
marshaler: tracesMarshaler})
|
||||
marshaler: tracesMarshaler,
|
||||
})
|
||||
payloads = append(payloads, testPayload{
|
||||
name: "md_trace_request",
|
||||
message: testdata.GenerateTraces(2),
|
||||
marshaler: tracesMarshaler})
|
||||
marshaler: tracesMarshaler,
|
||||
})
|
||||
payloads = append(payloads, testPayload{
|
||||
name: "lg_trace_request",
|
||||
message: testdata.GenerateTraces(50),
|
||||
marshaler: tracesMarshaler})
|
||||
marshaler: tracesMarshaler,
|
||||
})
|
||||
|
||||
// metric payloads
|
||||
metricsMarshaler := &metricsMarshaler{Marshaler: &pmetric.ProtoMarshaler{}}
|
||||
payloads = append(payloads, testPayload{
|
||||
name: "sm_metric_request",
|
||||
message: testdata.GenerateMetrics(1),
|
||||
marshaler: metricsMarshaler})
|
||||
marshaler: metricsMarshaler,
|
||||
})
|
||||
payloads = append(payloads, testPayload{
|
||||
name: "md_metric_request",
|
||||
message: testdata.GenerateMetrics(2),
|
||||
marshaler: metricsMarshaler})
|
||||
marshaler: metricsMarshaler,
|
||||
})
|
||||
payloads = append(payloads, testPayload{
|
||||
name: "lg_metric_request",
|
||||
message: testdata.GenerateMetrics(50),
|
||||
marshaler: metricsMarshaler})
|
||||
marshaler: metricsMarshaler,
|
||||
})
|
||||
|
||||
return payloads
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,12 +57,14 @@ func TestNewDefaultClientConfig(t *testing.T) {
|
|||
|
||||
assert.Equal(t, expected, result)
|
||||
}
|
||||
|
||||
func TestNewDefaultKeepaliveServerParameters(t *testing.T) {
|
||||
expectedParams := &KeepaliveServerParameters{}
|
||||
params := NewDefaultKeepaliveServerParameters()
|
||||
|
||||
assert.Equal(t, expectedParams, params)
|
||||
}
|
||||
|
||||
func TestNewDefaultKeepaliveEnforcementPolicy(t *testing.T) {
|
||||
expectedPolicy := &KeepaliveEnforcementPolicy{}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,10 @@ import (
|
|||
|
||||
type ctxKey struct{}
|
||||
|
||||
var oneCtxKey = ctxKey{}
|
||||
var otherCtxKey = ctxKey{}
|
||||
var (
|
||||
oneCtxKey = ctxKey{}
|
||||
otherCtxKey = ctxKey{}
|
||||
)
|
||||
|
||||
func TestWrapServerStream(t *testing.T) {
|
||||
ctx := context.WithValue(context.TODO(), oneCtxKey, 1)
|
||||
|
|
|
|||
|
|
@ -33,8 +33,11 @@ import (
|
|||
"go.opentelemetry.io/collector/extension/auth"
|
||||
)
|
||||
|
||||
const headerContentEncoding = "Content-Encoding"
|
||||
const defaultMaxRequestBodySize = 20 * 1024 * 1024 // 20MiB
|
||||
const (
|
||||
headerContentEncoding = "Content-Encoding"
|
||||
defaultMaxRequestBodySize = 20 * 1024 * 1024 // 20MiB
|
||||
)
|
||||
|
||||
var defaultCompressionAlgorithms = []string{"", "gzip", "zstd", "zlib", "snappy", "deflate", "lz4"}
|
||||
|
||||
// ClientConfig defines settings for creating an HTTP client.
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ import (
|
|||
"go.opentelemetry.io/collector/extension/auth/authtest"
|
||||
)
|
||||
|
||||
type customRoundTripper struct {
|
||||
}
|
||||
type customRoundTripper struct{}
|
||||
|
||||
var _ http.RoundTripper = (*customRoundTripper)(nil)
|
||||
|
||||
|
|
@ -430,7 +429,8 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
|
|||
host: &mockHost{
|
||||
ext: map[component.ID]component.Component{
|
||||
mockID: &authtest.MockClient{
|
||||
ResultRoundTripper: &customRoundTripper{}, MustError: true},
|
||||
ResultRoundTripper: &customRoundTripper{}, MustError: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func Example_opaqueString() {
|
|||
panic(err)
|
||||
}
|
||||
fmt.Printf("encoded cfg (YAML) is:\n%s\n\n", string(bytes))
|
||||
//Output: encoded cfg (YAML) is:
|
||||
// Output: encoded cfg (YAML) is:
|
||||
// censored: '[REDACTED]'
|
||||
// uncensored: not sensitive
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ func Example_opaqueSlice() {
|
|||
panic(err)
|
||||
}
|
||||
fmt.Printf("encoded cfg (JSON) is\n%s\n\n", string(bytes))
|
||||
//Output: encoded cfg (JSON) is
|
||||
// Output: encoded cfg (JSON) is
|
||||
// {
|
||||
// "Censored": [
|
||||
// "[REDACTED]",
|
||||
|
|
@ -91,10 +91,10 @@ func Example_opaqueMap() {
|
|||
panic(err)
|
||||
}
|
||||
fmt.Printf("encoded cfg (YAML) is:\n%s\n\n", string(bytes))
|
||||
//Output: encoded cfg (YAML) is:
|
||||
//censored:
|
||||
// Output: encoded cfg (YAML) is:
|
||||
// censored:
|
||||
// token: '[REDACTED]'
|
||||
//uncensored:
|
||||
// uncensored:
|
||||
// key: cloud.zone
|
||||
// value: zone-1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var _ encoding.TextMarshaler = (*Level)(nil)
|
||||
var _ encoding.TextUnmarshaler = (*Level)(nil)
|
||||
var (
|
||||
_ encoding.TextMarshaler = (*Level)(nil)
|
||||
_ encoding.TextUnmarshaler = (*Level)(nil)
|
||||
)
|
||||
|
||||
func TestUnmarshalText(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func TestErrorRecordedIfFileDeleted(t *testing.T) {
|
|||
|
||||
loader.returnErrorOnSubsequentCalls("test error on reload")
|
||||
|
||||
err = os.WriteFile(filePath, []byte("some_data"), 0600)
|
||||
err = os.WriteFile(filePath, []byte("some_data"), 0o600)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Eventually(t, func() bool {
|
||||
|
|
|
|||
|
|
@ -441,11 +441,11 @@ func TestLoadTLSServerConfigFailing(t *testing.T) {
|
|||
}
|
||||
|
||||
func overwriteClientCA(t *testing.T, targetFilePath string, testdataFileName string) {
|
||||
targetFile, err := os.OpenFile(filepath.Clean(targetFilePath), os.O_RDWR, 0600)
|
||||
targetFile, err := os.OpenFile(filepath.Clean(targetFilePath), os.O_RDWR, 0o600)
|
||||
require.NoError(t, err)
|
||||
|
||||
testdataFilePath := filepath.Join("testdata", testdataFileName)
|
||||
testdataFile, err := os.OpenFile(filepath.Clean(testdataFilePath), os.O_RDONLY, 0200)
|
||||
testdataFile, err := os.OpenFile(filepath.Clean(testdataFilePath), os.O_RDONLY, 0o200)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = io.Copy(targetFile, testdataFile)
|
||||
|
|
|
|||
|
|
@ -287,7 +287,8 @@ func useExpandValue() mapstructure.DecodeHookFuncType {
|
|||
return func(
|
||||
_ reflect.Type,
|
||||
to reflect.Type,
|
||||
data any) (any, error) {
|
||||
data any,
|
||||
) (any, error) {
|
||||
if exp, ok := data.(expandedValue); ok {
|
||||
v := castTo(exp, to.Kind() == reflect.String)
|
||||
// See https://github.com/open-telemetry/opentelemetry-collector/issues/10949
|
||||
|
|
|
|||
|
|
@ -449,15 +449,13 @@ func (ec *EmbeddedConfig2) Unmarshal(component *Conf) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type EmbeddedConfigWithError struct {
|
||||
}
|
||||
type EmbeddedConfigWithError struct{}
|
||||
|
||||
func (ecwe *EmbeddedConfigWithError) Unmarshal(_ *Conf) error {
|
||||
return errors.New("embedded error")
|
||||
}
|
||||
|
||||
type EmbeddedConfigWithMarshalError struct {
|
||||
}
|
||||
type EmbeddedConfigWithMarshalError struct{}
|
||||
|
||||
func (ecwe EmbeddedConfigWithMarshalError) Marshal(_ *Conf) error {
|
||||
return errors.New("marshaling error")
|
||||
|
|
@ -864,7 +862,8 @@ func TestExpandedValue(t *testing.T) {
|
|||
"key": expandedValue{
|
||||
Value: 0xdeadbeef,
|
||||
Original: "original",
|
||||
}})
|
||||
},
|
||||
})
|
||||
assert.Equal(t, 0xdeadbeef, cm.Get("key"))
|
||||
assert.Equal(t, map[string]any{"key": 0xdeadbeef}, cm.ToStringMap())
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func Example_simpleUnmarshaling() {
|
|||
panic(err)
|
||||
}
|
||||
fmt.Printf("Configuration contains the following:\nDisk: %q\nScrape: %s\n", scrapeInfo.Disk, scrapeInfo.Scrape)
|
||||
//Output: Configuration contains the following:
|
||||
// Output: Configuration contains the following:
|
||||
// Disk: "c"
|
||||
// Scrape: 5s
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ func Example_embeddedUnmarshaling() {
|
|||
panic(err)
|
||||
}
|
||||
fmt.Printf("Configuration contains the following:\nDisk: %q\nScrape: %s\nEnabled: %v\n", scrapeInfo.Disk, scrapeInfo.Scrape, scrapeInfo.Enabled)
|
||||
//Output: Configuration contains the following:
|
||||
// Output: Configuration contains the following:
|
||||
// Disk: "c"
|
||||
// Scrape: 5s
|
||||
// Enabled: true
|
||||
|
|
@ -105,7 +105,7 @@ func Example_embeddedManualUnmarshaling() {
|
|||
panic(err)
|
||||
}
|
||||
fmt.Printf("Configuration contains the following:\nNetworks: %q\nWifi: %v\nEnabled: %v\n", scrapeInfo.Networks, scrapeInfo.Wifi, scrapeInfo.Enabled)
|
||||
//Output: Configuration contains the following:
|
||||
// Output: Configuration contains the following:
|
||||
// Networks: ["eth0" "eth1" "wlan0"]
|
||||
// Wifi: true
|
||||
// Enabled: true
|
||||
|
|
@ -121,7 +121,7 @@ func Example_manualUnmarshaling() {
|
|||
panic(err)
|
||||
}
|
||||
fmt.Printf("Configuration contains the following:\nDisk: %q\nScrape: %s\n", scrapeInfo.Disk, scrapeInfo.Scrape)
|
||||
//Output: Configuration contains the following:
|
||||
// Output: Configuration contains the following:
|
||||
// Disk: "Beatles"
|
||||
// Scrape: 10s
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func TestResolverExpandEnvVars(t *testing.T) {
|
||||
var testCases = []struct {
|
||||
testCases := []struct {
|
||||
name string // test case name (also file name containing config yaml)
|
||||
}{
|
||||
{name: "expand-with-no-env.yaml"},
|
||||
|
|
@ -75,7 +75,8 @@ func TestResolverExpandMapAndSliceValues(t *testing.T) {
|
|||
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
|
||||
return NewRetrieved(map[string]any{
|
||||
"test_map": map[string]any{"recv": "${test:MAP_VALUE}"},
|
||||
"test_slice": []any{"${test:MAP_VALUE}"}})
|
||||
"test_slice": []any{"${test:MAP_VALUE}"},
|
||||
})
|
||||
})
|
||||
|
||||
const receiverExtraMapValue = "some map value"
|
||||
|
|
@ -90,7 +91,8 @@ func TestResolverExpandMapAndSliceValues(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
expectedMap := map[string]any{
|
||||
"test_map": map[string]any{"recv": receiverExtraMapValue},
|
||||
"test_slice": []any{receiverExtraMapValue}}
|
||||
"test_slice": []any{receiverExtraMapValue},
|
||||
}
|
||||
assert.Equal(t, expectedMap, cfgMap.ToStringMap())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -408,7 +408,8 @@ func TestRecursiveMaps(t *testing.T) {
|
|||
Env: ENV2{
|
||||
Env2: Value{
|
||||
Value: 123,
|
||||
}},
|
||||
},
|
||||
},
|
||||
Inline: "inline {env2: \"{value: 123}\"}",
|
||||
}},
|
||||
cfg,
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@ const (
|
|||
optionSkip = "-"
|
||||
)
|
||||
|
||||
var (
|
||||
errNonStringEncodedKey = errors.New("non string-encoded key")
|
||||
)
|
||||
var errNonStringEncodedKey = errors.New("non string-encoded key")
|
||||
|
||||
// tagInfo stores the mapstructure tag details.
|
||||
type tagInfo struct {
|
||||
|
|
|
|||
|
|
@ -49,14 +49,12 @@ func (fmp *provider) createClient() (*http.Client, error) {
|
|||
return &http.Client{}, nil
|
||||
case HTTPSScheme:
|
||||
pool, err := x509.SystemCertPool()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create a cert pool: %w", err)
|
||||
}
|
||||
|
||||
if fmp.caCertPath != "" {
|
||||
cert, err := os.ReadFile(filepath.Clean(fmp.caCertPath))
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read CA from %q URI: %w", fmp.caCertPath, err)
|
||||
}
|
||||
|
|
@ -89,7 +87,6 @@ func (fmp *provider) Retrieve(_ context.Context, uri string, _ confmap.WatcherFu
|
|||
}
|
||||
|
||||
client, err := fmp.createClient()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to configure http transport layer: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ func answerGet(w http.ResponseWriter, _ *http.Request) {
|
|||
// https://go.dev/src/crypto/tls/generate_cert.go
|
||||
func generateCertificate(hostname string) (cert string, key string, err error) {
|
||||
priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Failed to generate private key: %w", err)
|
||||
}
|
||||
|
|
@ -62,7 +61,6 @@ func generateCertificate(hostname string) (cert string, key string, err error) {
|
|||
notAfter := notBefore.Add(time.Hour * 12)
|
||||
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
|
||||
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
|
||||
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Failed to generate serial number: %w", err)
|
||||
}
|
||||
|
|
@ -81,7 +79,6 @@ func generateCertificate(hostname string) (cert string, key string, err error) {
|
|||
DNSNames: []string{hostname},
|
||||
}
|
||||
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
|
||||
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Failed to create certificate: %w", err)
|
||||
}
|
||||
|
|
@ -100,13 +97,11 @@ func generateCertificate(hostname string) (cert string, key string, err error) {
|
|||
}
|
||||
|
||||
keyOut, err := os.CreateTemp("", "key*.pem")
|
||||
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Failed to open key.pem for writing: %w", err)
|
||||
}
|
||||
|
||||
privBytes, err := x509.MarshalPKCS8PrivateKey(priv)
|
||||
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Unable to marshal private key: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,7 +302,8 @@ func TestBackwardsCompatibilityForFilePath(t *testing.T) {
|
|||
return nil, errors.New(uri)
|
||||
}),
|
||||
},
|
||||
ConverterFactories: nil})
|
||||
ConverterFactories: nil,
|
||||
})
|
||||
if tt.expectBuildErr {
|
||||
assert.Error(t, err)
|
||||
return
|
||||
|
|
@ -324,7 +325,8 @@ func TestResolver(t *testing.T) {
|
|||
return nil
|
||||
}}),
|
||||
},
|
||||
ConverterFactories: nil})
|
||||
ConverterFactories: nil,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, errN := resolver.Resolve(context.Background())
|
||||
require.NoError(t, errN)
|
||||
|
|
@ -355,7 +357,8 @@ func TestResolverNewLinesInOpaqueValue(t *testing.T) {
|
|||
_, err := NewResolver(ResolverSettings{
|
||||
URIs: []string{"mock:receivers:\n nop:\n"},
|
||||
ProviderFactories: []ProviderFactory{newMockProvider(&mockProvider{retM: map[string]any{}})},
|
||||
ConverterFactories: nil})
|
||||
ConverterFactories: nil,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -363,7 +366,8 @@ func TestResolverNoLocations(t *testing.T) {
|
|||
_, err := NewResolver(ResolverSettings{
|
||||
URIs: []string{},
|
||||
ProviderFactories: []ProviderFactory{newMockProvider(&mockProvider{})},
|
||||
ConverterFactories: nil})
|
||||
ConverterFactories: nil,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -371,7 +375,8 @@ func TestResolverNoProviders(t *testing.T) {
|
|||
_, err := NewResolver(ResolverSettings{
|
||||
URIs: []string{filepath.Join("testdata", "config.yaml")},
|
||||
ProviderFactories: nil,
|
||||
ConverterFactories: nil})
|
||||
ConverterFactories: nil,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +384,8 @@ func TestResolverShutdownClosesWatch(t *testing.T) {
|
|||
resolver, err := NewResolver(ResolverSettings{
|
||||
URIs: []string{filepath.Join("testdata", "config.yaml")},
|
||||
ProviderFactories: []ProviderFactory{newFileProvider(t)},
|
||||
ConverterFactories: nil})
|
||||
ConverterFactories: nil,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, errN := resolver.Resolve(context.Background())
|
||||
require.NoError(t, errN)
|
||||
|
|
|
|||
Loading…
Reference in New Issue