From 79e6c41adb7ea61a2055664f1481c3a4eb06ac24 Mon Sep 17 00:00:00 2001 From: Jack Warren Date: Thu, 12 Oct 2023 16:52:07 -0400 Subject: [PATCH] [DDO-3215] Fix v3 version upsert paths (#327) --- sherlock/internal/api/api_test.go | 32 +++++++++++++++++++ .../api/sherlock/app_version_v3_upsert.go | 2 +- .../api/sherlock/chart_version_v3_upsert.go | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 sherlock/internal/api/api_test.go diff --git a/sherlock/internal/api/api_test.go b/sherlock/internal/api/api_test.go new file mode 100644 index 000000000..aa03dbe38 --- /dev/null +++ b/sherlock/internal/api/api_test.go @@ -0,0 +1,32 @@ +package api + +import ( + "embed" + "github.com/stretchr/testify/assert" + "path" + "regexp" + "testing" +) + +//go:embed * +var apiFiles embed.FS +var capsInApiPathRegex = regexp.MustCompile(`/api/\w*[A-Z]`) + +func TestApiFiles(t *testing.T) { + validateApiPathsInDirectory(t, ".") +} + +func validateApiPathsInDirectory(t *testing.T, subdirectory string) { + entries, err := apiFiles.ReadDir(subdirectory) + assert.NoError(t, err) + for _, entry := range entries { + filesystemPath := path.Join(subdirectory, entry.Name()) + if entry.IsDir() { + validateApiPathsInDirectory(t, filesystemPath) + } else { + data, err := apiFiles.ReadFile(filesystemPath) + assert.NoError(t, err, "file %s read error", filesystemPath) + assert.Falsef(t, capsInApiPathRegex.Match(data), "file %s contains an API path with capitalized letters (matching %s)", filesystemPath, capsInApiPathRegex.String()) + } + } +} diff --git a/sherlock/internal/api/sherlock/app_version_v3_upsert.go b/sherlock/internal/api/sherlock/app_version_v3_upsert.go index f4be506e6..c034a31a4 100644 --- a/sherlock/internal/api/sherlock/app_version_v3_upsert.go +++ b/sherlock/internal/api/sherlock/app_version_v3_upsert.go @@ -21,7 +21,7 @@ import ( // @param appVersion body AppVersionV3Create true "The AppVersion to upsert" // @success 201 {object} AppVersionV3 // @failure 400,403,404,407,409,500 {object} errors.ErrorResponse -// @router /api/appVersions/v3 [post] +// @router /api/app-versions/v3 [post] func appVersionsV3Upsert(ctx *gin.Context) { db, err := authentication.MustUseDB(ctx) if err != nil { diff --git a/sherlock/internal/api/sherlock/chart_version_v3_upsert.go b/sherlock/internal/api/sherlock/chart_version_v3_upsert.go index db39bb48d..741171cce 100644 --- a/sherlock/internal/api/sherlock/chart_version_v3_upsert.go +++ b/sherlock/internal/api/sherlock/chart_version_v3_upsert.go @@ -21,7 +21,7 @@ import ( // @param chartVersion body ChartVersionV3Create true "The ChartVersion to upsert" // @success 201 {object} ChartVersionV3 // @failure 400,403,404,407,409,500 {object} errors.ErrorResponse -// @router /api/chartVersions/v3 [post] +// @router /api/chart-versions/v3 [post] func chartVersionsV3Upsert(ctx *gin.Context) { db, err := authentication.MustUseDB(ctx) if err != nil {