Skip to content

Commit

Permalink
Validate that quickstart names match in validate_quickstarts
Browse files Browse the repository at this point in the history
  • Loading branch information
randomnetcat committed Jun 21, 2024
1 parent a859e77 commit cdcb2ea
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cmd/validate/validate_quickstarts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -60,12 +61,14 @@ func validateQuickStartStructure() {
handleFileErr(filePath, err)

m := regexp.MustCompile("metadata.ya?ml$")
quickstartsFileName := filePath
metadataFileName := filePath

if _, err = os.Stat(m.ReplaceAllString(quickstartsFileName, metadata.Name+".yml")); err == nil {
quickstartsFileName = m.ReplaceAllString(quickstartsFileName, metadata.Name+".yml")
var quickstartsFileName string

if _, err = os.Stat(m.ReplaceAllString(metadataFileName, metadata.Name+".yml")); err == nil {
quickstartsFileName = m.ReplaceAllString(metadataFileName, metadata.Name+".yml")
} else {
quickstartsFileName = m.ReplaceAllString(quickstartsFileName, metadata.Name+".yaml")
quickstartsFileName = m.ReplaceAllString(metadataFileName, metadata.Name+".yaml")
}
yamlfile, err = ioutil.ReadFile(quickstartsFileName)
handleFileErr(quickstartsFileName, err)
Expand All @@ -76,6 +79,21 @@ func validateQuickStartStructure() {
err = json.Unmarshal(jsonContent, &content)
handleFileErr(quickstartsFileName, err)

var contentMetadata = content.Metadata
err = validation.ValidateStruct(&contentMetadata,
validation.Field(&contentMetadata.Name,
validation.In(metadata.Name).Error(
fmt.Sprintf("The names in %s and %s must match (got %s and %s)",
metadataFileName,
quickstartsFileName,
metadata.Name,
contentMetadata.Name,
),
),
),
)
handleFileErr(quickstartsFileName, err)

var spec = content.Spec
err = validation.ValidateStruct(&spec,
validation.Field(&spec.DisplayName, validation.Required),
Expand Down

0 comments on commit cdcb2ea

Please sign in to comment.