Skip to content

Commit

Permalink
Feature flag assertion validations
Browse files Browse the repository at this point in the history
  • Loading branch information
jtigger committed May 3, 2022
1 parent a5795e4 commit 8c121ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/assertions/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"github.com/k14s/starlark-go/starlark"
"github.com/vmware-tanzu/carvel-ytt/pkg/feature"
"github.com/vmware-tanzu/carvel-ytt/pkg/template"
"github.com/vmware-tanzu/carvel-ytt/pkg/yamlmeta"
)
Expand All @@ -23,9 +24,13 @@ const (
// When a Node's value is invalid, the errors are collected and returned in an AssertCheck.
// Otherwise, returns empty AssertCheck and nil error.
func ProcessAndRunValidations(n yamlmeta.Node, threadName string) (AssertCheck, error) {
if !feature.Flags().IsEnabled(feature.Validations) {
return AssertCheck{}, nil
}
if n == nil {
return AssertCheck{}, nil
}

err := yamlmeta.Walk(n, &convertAssertAnnsToValidations{})
if err != nil {
return AssertCheck{}, err
Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/template/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
package template_test

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cmdtpl "github.com/vmware-tanzu/carvel-ytt/pkg/cmd/template"
"github.com/vmware-tanzu/carvel-ytt/pkg/cmd/ui"
"github.com/vmware-tanzu/carvel-ytt/pkg/feature"
"github.com/vmware-tanzu/carvel-ytt/pkg/files"
)

// TestMain is invoked when any tests are run in this package, *instead of* those tests being run directly.
// This allows for setup to occur before *any* test is run.
func TestMain(m *testing.M) {
// Enable experimental code
feature.Flags().Enable(feature.Validations)

exitVal := m.Run() // execute the specified tests

os.Exit(exitVal) // required in order to properly report the error level when tests fail.
}

func TestLoad(t *testing.T) {
yamlTplData := []byte(`
#@ load("@ytt:data", "data")
Expand Down
5 changes: 3 additions & 2 deletions pkg/feature/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import "fmt"

// Names of features that can be toggled
const (
Noop = "noop"
Noop = "noop"
Validations = "validations"
)

// allFeatures is the total list of features. It must contain all the constants defined, above.
var allFeatures = []string{Noop}
var allFeatures = []string{Noop, Validations}

// Flags returns the singleton instance of feature flags.
func Flags() *Flagset {
Expand Down

0 comments on commit 8c121ed

Please sign in to comment.