From a09020f8913c9bd29b4a7dfdb20ef59ce645efa0 Mon Sep 17 00:00:00 2001 From: Haveiss Date: Thu, 25 Apr 2024 13:27:38 +0700 Subject: [PATCH] feat(type): add support for metric asset --- core/asset/type.go | 10 ++++++---- core/asset/type_test.go | 3 ++- internal/server/v1beta1/type_test.go | 4 ++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/core/asset/type.go b/core/asset/type.go index ea78f2c2..6875df74 100644 --- a/core/asset/type.go +++ b/core/asset/type.go @@ -9,6 +9,7 @@ const ( TypeApplication Type = "application" TypeModel Type = "model" TypeQuery Type = "query" + TypeMetric Type = "metric" ) // AllSupportedTypes holds a list of all supported types struct @@ -21,6 +22,7 @@ var AllSupportedTypes = []Type{ TypeApplication, TypeModel, TypeQuery, + TypeMetric, } // Type specifies a supported type name @@ -33,10 +35,10 @@ func (t Type) String() string { // IsValid will validate whether the typename is valid or not func (t Type) IsValid() bool { - switch t { - case TypeTable, TypeJob, TypeDashboard, TypeTopic, - TypeFeatureTable, TypeApplication, TypeModel, TypeQuery: - return true + for _, supportedType := range AllSupportedTypes { + if t == supportedType { + return true + } } return false } diff --git a/core/asset/type_test.go b/core/asset/type_test.go index 1034e53c..a6b282c2 100644 --- a/core/asset/type_test.go +++ b/core/asset/type_test.go @@ -16,6 +16,7 @@ func TestTypeString(t *testing.T) { TypeApplication: "application", TypeModel: "model", TypeQuery: "query", + TypeMetric: "metric", } { t.Run((string)(typ), func(t *testing.T) { assert.Equal(t, expected, typ.String()) @@ -25,7 +26,7 @@ func TestTypeString(t *testing.T) { func TestTypeIsValid(t *testing.T) { for _, typ := range []Type{ - "dashboard", "job", "table", "topic", "feature_table", "application", "model", "query", + "dashboard", "job", "table", "topic", "feature_table", "application", "model", "query", "metric", } { t.Run((string)(typ), func(t *testing.T) { assert.Truef(t, typ.IsValid(), "%s should be valid", typ) diff --git a/internal/server/v1beta1/type_test.go b/internal/server/v1beta1/type_test.go index 8619d553..8e2a6d51 100644 --- a/internal/server/v1beta1/type_test.go +++ b/internal/server/v1beta1/type_test.go @@ -90,6 +90,10 @@ func TestGetTypes(t *testing.T) { Name: "query", Count: 0, }, + { + Name: "metric", + Count: 0, + }, }, }