From 0bf40d39eabd00f7a2b391e961c42a7104045c21 Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Thu, 9 May 2024 10:55:23 -0700 Subject: [PATCH] [mdatagen] use main as package for cmd types (#10130) This allows us to enabled package test generation for mdatagen itself (and for telemetrygen in contrib) Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- cmd/mdatagen/{package_test.go => generated_package_test.go} | 3 +-- cmd/mdatagen/main.go | 5 +++++ cmd/mdatagen/metadata.yaml | 2 ++ cmd/mdatagen/templates/package_test.go.tmpl | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) rename cmd/mdatagen/{package_test.go => generated_package_test.go} (60%) diff --git a/cmd/mdatagen/package_test.go b/cmd/mdatagen/generated_package_test.go similarity index 60% rename from cmd/mdatagen/package_test.go rename to cmd/mdatagen/generated_package_test.go index 5cd502ca564..2a21d3c7c86 100644 --- a/cmd/mdatagen/package_test.go +++ b/cmd/mdatagen/generated_package_test.go @@ -1,5 +1,4 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 +// Code generated by mdatagen. DO NOT EDIT. package main diff --git a/cmd/mdatagen/main.go b/cmd/mdatagen/main.go index 959275c0226..ee4b719aef5 100644 --- a/cmd/mdatagen/main.go +++ b/cmd/mdatagen/main.go @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +//go:generate mdatagen metadata.yaml + package main import ( @@ -204,6 +206,9 @@ func templatize(tmplFile string, md metadata) *template.Template { "isConnector": func() bool { return md.Status.Class == "connector" }, + "isCommand": func() bool { + return md.Status.Class == "cmd" + }, "supportsLogs": func() bool { for _, signals := range md.Status.Stability { for _, s := range signals { diff --git a/cmd/mdatagen/metadata.yaml b/cmd/mdatagen/metadata.yaml index 65bb097a962..bc18609e74c 100644 --- a/cmd/mdatagen/metadata.yaml +++ b/cmd/mdatagen/metadata.yaml @@ -2,5 +2,7 @@ type: mdatagen status: class: cmd + stability: + alpha: [metrics] codeowners: active: [dmitryax] \ No newline at end of file diff --git a/cmd/mdatagen/templates/package_test.go.tmpl b/cmd/mdatagen/templates/package_test.go.tmpl index f0e0ba2e795..93446b7a5d7 100644 --- a/cmd/mdatagen/templates/package_test.go.tmpl +++ b/cmd/mdatagen/templates/package_test.go.tmpl @@ -1,6 +1,6 @@ // Code generated by mdatagen. DO NOT EDIT. -package {{ .Package }} +package {{ if isCommand -}}main{{ else }}{{ .Package }}{{- end }} import ( "testing"