Skip to content

Commit

Permalink
Merge pull request #292 from b4nst/feat/add-values-arg-to-vet-command
Browse files Browse the repository at this point in the history
Add `--values` arg to `timoni mod vet` cmd
  • Loading branch information
stefanprodan authored Dec 20, 2023
2 parents 217cab9 + b8b05b8 commit f0e4ed1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
22 changes: 18 additions & 4 deletions cmd/timoni/mod_vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ var vetModCmd = &cobra.Command{
}

type vetModFlags struct {
path string
pkg flags.Package
debug bool
name string
path string
pkg flags.Package
debug bool
valuesFiles []string
name string
}

var vetModArgs vetModFlags
Expand All @@ -63,6 +64,8 @@ func init() {
vetModCmd.Flags().VarP(&vetModArgs.pkg, vetModArgs.pkg.Type(), vetModArgs.pkg.Shorthand(), vetModArgs.pkg.Description())
vetModCmd.Flags().BoolVar(&vetModArgs.debug, "debug", false,
"Use debug_values.cue if found in the module root instead of the default values.")
vetModCmd.Flags().StringSliceVarP(&vetModArgs.valuesFiles, "values", "f", nil,
"The local path to values files (cue, yaml or json format).")
modCmd.AddCommand(vetModCmd)
}

Expand Down Expand Up @@ -136,6 +139,17 @@ func runVetModCmd(cmd *cobra.Command, args []string) error {
return fmt.Errorf("build failed: %w", err)
}

if len(vetModArgs.valuesFiles) > 0 {
valuesCue, err := convertToCue(cmd, vetModArgs.valuesFiles)
if err != nil {
return err
}
err = builder.MergeValuesFile(valuesCue)
if err != nil {
return err
}
}

buildResult, err := builder.Build(tags...)
if err != nil {
return describeErr(fetcher.GetModuleRoot(), "validation failed", err)
Expand Down
29 changes: 29 additions & 0 deletions cmd/timoni/mod_vet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ func TestModVet(t *testing.T) {
})
}

func TestModVetWithValue(t *testing.T) {
modPath := "testdata/module"
valuesPath := "testdata/module-values"

t.Run("vets module with correct values", func(t *testing.T) {
g := NewWithT(t)
output, err := executeCommand(fmt.Sprintf(
"mod vet %s -p main --values %s",
modPath, valuesPath+"/client-only.cue",
))
g.Expect(err).ToNot(HaveOccurred())

g.Expect(output).To(ContainSubstring("timoni:latest-dev@sha256:"))
g.Expect(output).To(ContainSubstring("timoni.sh/test valid"))
g.Expect(output).To(ContainSubstring("/default"))
})

t.Run("fails to vet with incorrect values", func(t *testing.T) {
g := NewWithT(t)
_, err := executeCommand(fmt.Sprintf(
"mod vet %s -p main --values %s",
modPath, valuesPath+"/invalid.cue",
))
g.Expect(err).To(HaveOccurred())
g.Expect(err.Error()).To(ContainSubstring("validation failed"))
g.Expect(err.Error()).To(ContainSubstring("mismatched types string and bool"))
})
}

func TestModVetSetName(t *testing.T) {
modPath := "testdata/module"

Expand Down

0 comments on commit f0e4ed1

Please sign in to comment.