mirror of
https://github.com/helm/helm.git
synced 2026-08-09 09:33:14 +00:00
Merge pull request #32424 from mmorel-35/testifylint-manual-assert-pkg-9
chore(pkg): refactor: convert tests to testify assert/require part 9
This commit is contained in:
@@ -141,9 +141,7 @@ func TestCoalesceValues(t *testing.T) {
|
||||
)
|
||||
|
||||
vals, err := common.ReadValues(testCoalesceValuesYaml)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
// taking a copy of the values before passing it
|
||||
// to CoalesceValues as argument, so that we can
|
||||
@@ -152,9 +150,7 @@ func TestCoalesceValues(t *testing.T) {
|
||||
maps.Copy(valsCopy, vals)
|
||||
|
||||
v, err := CoalesceValues(c, vals)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
j, _ := json.MarshalIndent(v, "", " ")
|
||||
t.Logf("Coalesced Values: %s", string(j))
|
||||
|
||||
@@ -211,32 +207,26 @@ func TestCoalesceValues(t *testing.T) {
|
||||
|
||||
nullKeys := []string{"bottom", "right", "left", "front"}
|
||||
for _, nullKey := range nullKeys {
|
||||
if _, ok := v[nullKey]; ok {
|
||||
t.Errorf("Expected key %q to be removed, still present", nullKey)
|
||||
}
|
||||
_, ok := v[nullKey]
|
||||
assert.Falsef(t, ok, "Expected key %q to be removed, still present", nullKey)
|
||||
}
|
||||
|
||||
if _, ok := v["nested"].(map[string]any)["boat"]; ok {
|
||||
t.Error("Expected nested boat key to be removed, still present")
|
||||
}
|
||||
_, ok := v["nested"].(map[string]any)["boat"]
|
||||
assert.False(t, ok, "Expected nested boat key to be removed, still present")
|
||||
|
||||
subchart := v["pequod"].(map[string]any)
|
||||
if _, ok := subchart["boat"]; ok {
|
||||
t.Error("Expected subchart boat key to be removed, still present")
|
||||
}
|
||||
_, ok = subchart["boat"]
|
||||
assert.False(t, ok, "Expected subchart boat key to be removed, still present")
|
||||
|
||||
subsubchart := subchart["ahab"].(map[string]any)
|
||||
if _, ok := subsubchart["boat"]; ok {
|
||||
t.Error("Expected sub-subchart ahab boat key to be removed, still present")
|
||||
}
|
||||
_, ok = subsubchart["boat"]
|
||||
assert.False(t, ok, "Expected sub-subchart ahab boat key to be removed, still present")
|
||||
|
||||
if _, ok := subsubchart["nested"].(map[string]any)["boat"]; ok {
|
||||
t.Error("Expected sub-subchart nested boat key to be removed, still present")
|
||||
}
|
||||
_, ok = subsubchart["nested"].(map[string]any)["boat"]
|
||||
assert.False(t, ok, "Expected sub-subchart nested boat key to be removed, still present")
|
||||
|
||||
if _, ok := subsubchart["object"]; ok {
|
||||
t.Error("Expected sub-subchart object map to be removed, still present")
|
||||
}
|
||||
_, ok = subsubchart["object"]
|
||||
assert.False(t, ok, "Expected sub-subchart object map to be removed, still present")
|
||||
|
||||
// CoalesceValues should not mutate the passed arguments
|
||||
is.Equal(valsCopy, vals)
|
||||
@@ -306,9 +296,7 @@ func TestMergeValues(t *testing.T) {
|
||||
)
|
||||
|
||||
vals, err := common.ReadValues(testCoalesceValuesYaml)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
// taking a copy of the values before passing it
|
||||
// to MergeValues as argument, so that we can
|
||||
@@ -317,9 +305,7 @@ func TestMergeValues(t *testing.T) {
|
||||
maps.Copy(valsCopy, vals)
|
||||
|
||||
v, err := MergeValues(c, vals)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
j, _ := json.MarshalIndent(v, "", " ")
|
||||
t.Logf("Coalesced Values: %s", string(j))
|
||||
|
||||
@@ -377,25 +363,20 @@ func TestMergeValues(t *testing.T) {
|
||||
// removed.
|
||||
nullKeys := []string{"bottom", "right", "left", "front"}
|
||||
for _, nullKey := range nullKeys {
|
||||
if vv, ok := v[nullKey]; !ok {
|
||||
t.Errorf("Expected key %q to be present but it was removed", nullKey)
|
||||
} else if vv != nil {
|
||||
t.Errorf("Expected key %q to be null but it has a value of %v", nullKey, vv)
|
||||
}
|
||||
vv, ok := v[nullKey]
|
||||
assert.Truef(t, ok, "Expected key %q to be present but it was removed", nullKey)
|
||||
assert.Nilf(t, vv, "Expected key %q to be null but it has a value of %v", nullKey, vv)
|
||||
}
|
||||
|
||||
if _, ok := v["nested"].(map[string]any)["boat"]; !ok {
|
||||
t.Error("Expected nested boat key to be present but it was removed")
|
||||
}
|
||||
_, ok := v["nested"].(map[string]any)["boat"]
|
||||
assert.True(t, ok, "Expected nested boat key to be present but it was removed")
|
||||
|
||||
subchart := v["pequod"].(map[string]any)["ahab"].(map[string]any)
|
||||
if _, ok := subchart["boat"]; !ok {
|
||||
t.Error("Expected subchart boat key to be present but it was removed")
|
||||
}
|
||||
_, ok = subchart["boat"]
|
||||
assert.True(t, ok, "Expected subchart boat key to be present but it was removed")
|
||||
|
||||
if _, ok := subchart["nested"].(map[string]any)["bar"]; !ok {
|
||||
t.Error("Expected subchart nested bar key to be present but it was removed")
|
||||
}
|
||||
_, ok = subchart["nested"].(map[string]any)["bar"]
|
||||
assert.True(t, ok, "Expected subchart nested bar key to be present but it was removed")
|
||||
|
||||
// CoalesceValues should not mutate the passed arguments
|
||||
is.Equal(valsCopy, vals)
|
||||
@@ -433,47 +414,27 @@ func TestCoalesceTables(t *testing.T) {
|
||||
// otherwise the values are coalesced.
|
||||
CoalesceTables(dst, src)
|
||||
|
||||
if dst["name"] != "Ishmael" {
|
||||
t.Errorf("Unexpected name: %s", dst["name"])
|
||||
}
|
||||
if dst["occupation"] != "whaler" {
|
||||
t.Errorf("Unexpected occupation: %s", dst["occupation"])
|
||||
}
|
||||
assert.Equal(t, "Ishmael", dst["name"], "Unexpected name: %s", dst["name"])
|
||||
assert.Equal(t, "whaler", dst["occupation"], "Unexpected occupation: %s", dst["occupation"])
|
||||
|
||||
addr, ok := dst["address"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatal("Address went away.")
|
||||
}
|
||||
require.True(t, ok, "Address went away.")
|
||||
assert.Equal(t, "123 Spouter Inn Ct.", addr["street"].(string), "Unexpected address: %v", addr["street"])
|
||||
assert.Equal(t, "Nantucket", addr["city"].(string), "Unexpected city: %v", addr["city"])
|
||||
assert.Equal(t, "MA", addr["state"].(string), "Unexpected state: %v", addr["state"])
|
||||
|
||||
if addr["street"].(string) != "123 Spouter Inn Ct." {
|
||||
t.Errorf("Unexpected address: %v", addr["street"])
|
||||
}
|
||||
_, ok = addr["country"]
|
||||
assert.False(t, ok, "The country is not left out.")
|
||||
|
||||
if addr["city"].(string) != "Nantucket" {
|
||||
t.Errorf("Unexpected city: %v", addr["city"])
|
||||
}
|
||||
det, ok := dst["details"].(map[string]any)
|
||||
require.Truef(t, ok, "Details is the wrong type: %v", dst["details"])
|
||||
|
||||
if addr["state"].(string) != "MA" {
|
||||
t.Errorf("Unexpected state: %v", addr["state"])
|
||||
}
|
||||
_, ok = det["friends"]
|
||||
assert.True(t, ok, "Could not find your friends. Maybe you don't have any. :-(")
|
||||
assert.Equal(t, "pequod", dst["boat"].(string), "Expected boat string, got %v", dst["boat"])
|
||||
|
||||
if _, ok = addr["country"]; ok {
|
||||
t.Error("The country is not left out.")
|
||||
}
|
||||
|
||||
if det, ok := dst["details"].(map[string]any); !ok {
|
||||
t.Fatalf("Details is the wrong type: %v", dst["details"])
|
||||
} else if _, ok := det["friends"]; !ok {
|
||||
t.Error("Could not find your friends. Maybe you don't have any. :-(")
|
||||
}
|
||||
|
||||
if dst["boat"].(string) != "pequod" {
|
||||
t.Errorf("Expected boat string, got %v", dst["boat"])
|
||||
}
|
||||
|
||||
if _, ok = dst["hole"]; ok {
|
||||
t.Error("The hole still exists.")
|
||||
}
|
||||
_, ok = dst["hole"]
|
||||
assert.False(t, ok, "The hole still exists.")
|
||||
|
||||
dst2 := map[string]any{
|
||||
"name": "Ishmael",
|
||||
@@ -493,40 +454,21 @@ func TestCoalesceTables(t *testing.T) {
|
||||
// this happens when the --reuse-values flag is set but the chart has no modifications yet
|
||||
CoalesceTables(dst2, nil)
|
||||
|
||||
if dst2["name"] != "Ishmael" {
|
||||
t.Errorf("Unexpected name: %s", dst2["name"])
|
||||
}
|
||||
assert.Equal(t, "Ishmael", dst2["name"], "Unexpected name: %s", dst2["name"])
|
||||
|
||||
addr2, ok := dst2["address"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatal("Address went away.")
|
||||
}
|
||||
require.True(t, ok, "Address went away.")
|
||||
assert.Equal(t, "123 Spouter Inn Ct.", addr2["street"].(string), "Unexpected address: %v", addr2["street"])
|
||||
assert.Equal(t, "Nantucket", addr2["city"].(string), "Unexpected city: %v", addr2["city"])
|
||||
assert.Equal(t, "US", addr2["country"].(string), "Unexpected Country: %v", addr2["country"])
|
||||
|
||||
if addr2["street"].(string) != "123 Spouter Inn Ct." {
|
||||
t.Errorf("Unexpected address: %v", addr2["street"])
|
||||
}
|
||||
det2, ok := dst2["details"].(map[string]any)
|
||||
require.Truef(t, ok, "Details is the wrong type: %v", dst2["details"])
|
||||
|
||||
if addr2["city"].(string) != "Nantucket" {
|
||||
t.Errorf("Unexpected city: %v", addr2["city"])
|
||||
}
|
||||
|
||||
if addr2["country"].(string) != "US" {
|
||||
t.Errorf("Unexpected Country: %v", addr2["country"])
|
||||
}
|
||||
|
||||
if det2, ok := dst2["details"].(map[string]any); !ok {
|
||||
t.Fatalf("Details is the wrong type: %v", dst2["details"])
|
||||
} else if _, ok := det2["friends"]; !ok {
|
||||
t.Error("Could not find your friends. Maybe you don't have any. :-(")
|
||||
}
|
||||
|
||||
if dst2["boat"].(string) != "pequod" {
|
||||
t.Errorf("Expected boat string, got %v", dst2["boat"])
|
||||
}
|
||||
|
||||
if dst2["hole"].(string) != "black" {
|
||||
t.Errorf("Expected hole string, got %v", dst2["boat"])
|
||||
}
|
||||
_, ok = det2["friends"]
|
||||
assert.True(t, ok, "Could not find your friends. Maybe you don't have any. :-(")
|
||||
assert.Equal(t, "pequod", dst2["boat"].(string), "Expected boat string, got %v", dst2["boat"])
|
||||
assert.Equal(t, "black", dst2["hole"].(string), "Expected hole string, got %v", dst2["boat"])
|
||||
}
|
||||
|
||||
func TestMergeTables(t *testing.T) {
|
||||
@@ -561,51 +503,31 @@ func TestMergeTables(t *testing.T) {
|
||||
// otherwise the values are coalesced.
|
||||
MergeTables(dst, src)
|
||||
|
||||
if dst["name"] != "Ishmael" {
|
||||
t.Errorf("Unexpected name: %s", dst["name"])
|
||||
}
|
||||
if dst["occupation"] != "whaler" {
|
||||
t.Errorf("Unexpected occupation: %s", dst["occupation"])
|
||||
}
|
||||
assert.Equal(t, "Ishmael", dst["name"], "Unexpected name: %s", dst["name"])
|
||||
assert.Equal(t, "whaler", dst["occupation"], "Unexpected occupation: %s", dst["occupation"])
|
||||
|
||||
addr, ok := dst["address"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatal("Address went away.")
|
||||
}
|
||||
|
||||
if addr["street"].(string) != "123 Spouter Inn Ct." {
|
||||
t.Errorf("Unexpected address: %v", addr["street"])
|
||||
}
|
||||
|
||||
if addr["city"].(string) != "Nantucket" {
|
||||
t.Errorf("Unexpected city: %v", addr["city"])
|
||||
}
|
||||
|
||||
if addr["state"].(string) != "MA" {
|
||||
t.Errorf("Unexpected state: %v", addr["state"])
|
||||
}
|
||||
require.True(t, ok, "Address went away.")
|
||||
assert.Equal(t, "123 Spouter Inn Ct.", addr["street"].(string), "Unexpected address: %v", addr["street"])
|
||||
assert.Equal(t, "Nantucket", addr["city"].(string), "Unexpected city: %v", addr["city"])
|
||||
assert.Equal(t, "MA", addr["state"].(string), "Unexpected state: %v", addr["state"])
|
||||
|
||||
// This is one test that is different from CoalesceTables. Because country
|
||||
// is a nil value and it's not removed it's still present.
|
||||
if _, ok = addr["country"]; !ok {
|
||||
t.Error("The country is left out.")
|
||||
}
|
||||
_, ok = addr["country"]
|
||||
assert.True(t, ok, "The country is left out.")
|
||||
|
||||
if det, ok := dst["details"].(map[string]any); !ok {
|
||||
t.Fatalf("Details is the wrong type: %v", dst["details"])
|
||||
} else if _, ok := det["friends"]; !ok {
|
||||
t.Error("Could not find your friends. Maybe you don't have any. :-(")
|
||||
}
|
||||
det, ok := dst["details"].(map[string]any)
|
||||
require.Truef(t, ok, "Details is the wrong type: %v", dst["details"])
|
||||
|
||||
if dst["boat"].(string) != "pequod" {
|
||||
t.Errorf("Expected boat string, got %v", dst["boat"])
|
||||
}
|
||||
_, ok = det["friends"]
|
||||
assert.True(t, ok, "Could not find your friends. Maybe you don't have any. :-(")
|
||||
assert.Equal(t, "pequod", dst["boat"].(string), "Expected boat string, got %v", dst["boat"])
|
||||
|
||||
// This is one test that is different from CoalesceTables. Because hole
|
||||
// is a nil value and it's not removed it's still present.
|
||||
if _, ok = dst["hole"]; !ok {
|
||||
t.Error("The hole no longer exists.")
|
||||
}
|
||||
_, ok = dst["hole"]
|
||||
assert.True(t, ok, "The hole no longer exists.")
|
||||
|
||||
dst2 := map[string]any{
|
||||
"name": "Ishmael",
|
||||
@@ -626,44 +548,22 @@ func TestMergeTables(t *testing.T) {
|
||||
// this happens when the --reuse-values flag is set but the chart has no modifications yet
|
||||
MergeTables(dst2, nil)
|
||||
|
||||
if dst2["name"] != "Ishmael" {
|
||||
t.Errorf("Unexpected name: %s", dst2["name"])
|
||||
}
|
||||
assert.Equal(t, "Ishmael", dst2["name"], "Unexpected name: %s", dst2["name"])
|
||||
|
||||
addr2, ok := dst2["address"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatal("Address went away.")
|
||||
}
|
||||
require.True(t, ok, "Address went away.")
|
||||
assert.Equal(t, "123 Spouter Inn Ct.", addr2["street"].(string), "Unexpected address: %v", addr2["street"])
|
||||
assert.Equal(t, "Nantucket", addr2["city"].(string), "Unexpected city: %v", addr2["city"])
|
||||
assert.Equal(t, "US", addr2["country"].(string), "Unexpected Country: %v", addr2["country"])
|
||||
|
||||
if addr2["street"].(string) != "123 Spouter Inn Ct." {
|
||||
t.Errorf("Unexpected address: %v", addr2["street"])
|
||||
}
|
||||
det2, ok := dst2["details"].(map[string]any)
|
||||
require.Truef(t, ok, "Details is the wrong type: %v", dst2["details"])
|
||||
|
||||
if addr2["city"].(string) != "Nantucket" {
|
||||
t.Errorf("Unexpected city: %v", addr2["city"])
|
||||
}
|
||||
|
||||
if addr2["country"].(string) != "US" {
|
||||
t.Errorf("Unexpected Country: %v", addr2["country"])
|
||||
}
|
||||
|
||||
if det2, ok := dst2["details"].(map[string]any); !ok {
|
||||
t.Fatalf("Details is the wrong type: %v", dst2["details"])
|
||||
} else if _, ok := det2["friends"]; !ok {
|
||||
t.Error("Could not find your friends. Maybe you don't have any. :-(")
|
||||
}
|
||||
|
||||
if dst2["boat"].(string) != "pequod" {
|
||||
t.Errorf("Expected boat string, got %v", dst2["boat"])
|
||||
}
|
||||
|
||||
if dst2["hole"].(string) != "black" {
|
||||
t.Errorf("Expected hole string, got %v", dst2["boat"])
|
||||
}
|
||||
|
||||
if dst2["nilval"] != nil {
|
||||
t.Error("Expected nilvalue to have nil value but it does not")
|
||||
}
|
||||
_, ok = det2["friends"]
|
||||
assert.True(t, ok, "Could not find your friends. Maybe you don't have any. :-(")
|
||||
assert.Equal(t, "pequod", dst2["boat"].(string), "Expected boat string, got %v", dst2["boat"])
|
||||
assert.Equal(t, "black", dst2["hole"].(string), "Expected hole string, got %v", dst2["hole"])
|
||||
assert.Nil(t, dst2["nilval"], "Expected nilvalue to have nil value but it does not")
|
||||
}
|
||||
|
||||
func TestCoalesceValuesWarnings(t *testing.T) {
|
||||
@@ -716,9 +616,7 @@ func TestCoalesceValuesWarnings(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := coalesce(printf, c, vals, "", false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Logf("vals: %v", vals)
|
||||
assert.Contains(t, warnings, "warning: skipped value for level1.level2.level3.boat: Not a table.")
|
||||
@@ -926,7 +824,6 @@ func TestCoalesceValuesSubchartNilCleanedWhenUserPartiallyOverrides(t *testing.T
|
||||
|
||||
keyMapping, ok := childVals["keyMapping"].(map[string]any)
|
||||
is.True(ok, "keyMapping should be a map")
|
||||
|
||||
is.Equal("sha256", keyMapping["format"], "User override should be preserved")
|
||||
|
||||
_, ok = keyMapping["password"]
|
||||
|
||||
@@ -20,75 +20,47 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"helm.sh/helm/v4/pkg/chart/common"
|
||||
chart "helm.sh/helm/v4/pkg/chart/v2"
|
||||
)
|
||||
|
||||
func TestValidateAgainstSingleSchema(t *testing.T) {
|
||||
values, err := common.ReadValuesFile("./testdata/test-values.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading YAML file: %s", err)
|
||||
}
|
||||
schema, err := os.ReadFile("./testdata/test-values.schema.json")
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading YAML file: %s", err)
|
||||
}
|
||||
require.NoError(t, err, "Error reading YAML file")
|
||||
|
||||
if err := ValidateAgainstSingleSchema(values, schema); err != nil {
|
||||
t.Errorf("Error validating Values against Schema: %s", err)
|
||||
}
|
||||
schema, err := os.ReadFile("./testdata/test-values.schema.json")
|
||||
require.NoError(t, err, "Error reading YAML file")
|
||||
assert.NoErrorf(t, ValidateAgainstSingleSchema(values, schema), "Error validating Values against Schema")
|
||||
}
|
||||
|
||||
func TestValidateAgainstInvalidSingleSchema(t *testing.T) {
|
||||
values, err := common.ReadValuesFile("./testdata/test-values.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading YAML file: %s", err)
|
||||
}
|
||||
schema, err := os.ReadFile("./testdata/test-values-invalid.schema.json")
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading YAML file: %s", err)
|
||||
}
|
||||
require.NoError(t, err, "Error reading YAML file")
|
||||
|
||||
var errString string
|
||||
if err := ValidateAgainstSingleSchema(values, schema); err == nil {
|
||||
t.Fatal("Expected an error, but got nil")
|
||||
} else {
|
||||
errString = err.Error()
|
||||
}
|
||||
schema, err := os.ReadFile("./testdata/test-values-invalid.schema.json")
|
||||
require.NoError(t, err, "Error reading YAML file")
|
||||
|
||||
expectedErrString := `"file:///values.schema.json#" is not valid against metaschema: jsonschema validation failed with 'https://json-schema.org/draft/2020-12/schema#'
|
||||
- at '': got number, want boolean or object`
|
||||
if errString != expectedErrString {
|
||||
t.Errorf("Error string :\n`%s`\ndoes not match expected\n`%s`", errString, expectedErrString)
|
||||
}
|
||||
assert.EqualError(t, ValidateAgainstSingleSchema(values, schema), expectedErrString)
|
||||
}
|
||||
|
||||
func TestValidateAgainstSingleSchemaNegative(t *testing.T) {
|
||||
values, err := common.ReadValuesFile("./testdata/test-values-negative.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading YAML file: %s", err)
|
||||
}
|
||||
schema, err := os.ReadFile("./testdata/test-values.schema.json")
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading JSON file: %s", err)
|
||||
}
|
||||
require.NoError(t, err, "Error reading YAML file")
|
||||
|
||||
var errString string
|
||||
if err := ValidateAgainstSingleSchema(values, schema); err == nil {
|
||||
t.Fatal("Expected an error, but got nil")
|
||||
} else {
|
||||
errString = err.Error()
|
||||
}
|
||||
schema, err := os.ReadFile("./testdata/test-values.schema.json")
|
||||
require.NoError(t, err, "Error reading JSON file")
|
||||
|
||||
expectedErrString := `- at '': missing property 'employmentInfo'
|
||||
- at '/age': minimum: got -5, want 0
|
||||
`
|
||||
if errString != expectedErrString {
|
||||
t.Errorf("Error string :\n`%s`\ndoes not match expected\n`%s`", errString, expectedErrString)
|
||||
}
|
||||
assert.EqualError(t, ValidateAgainstSingleSchema(values, schema), expectedErrString)
|
||||
}
|
||||
|
||||
const subchartSchema = `{
|
||||
@@ -145,9 +117,7 @@ func TestValidateAgainstSchema(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if err := ValidateAgainstSchema(chrt, vals); err != nil {
|
||||
t.Errorf("Error validating Values against Schema: %s", err)
|
||||
}
|
||||
assert.NoErrorf(t, ValidateAgainstSchema(chrt, vals), "Error validating Values against Schema")
|
||||
}
|
||||
|
||||
func TestValidateAgainstSchemaNegative(t *testing.T) {
|
||||
@@ -170,19 +140,10 @@ func TestValidateAgainstSchemaNegative(t *testing.T) {
|
||||
"subchart": map[string]any{},
|
||||
}
|
||||
|
||||
var errString string
|
||||
if err := ValidateAgainstSchema(chrt, vals); err == nil {
|
||||
t.Fatal("Expected an error, but got nil")
|
||||
} else {
|
||||
errString = err.Error()
|
||||
}
|
||||
|
||||
expectedErrString := `subchart:
|
||||
- at '': missing property 'age'
|
||||
`
|
||||
if errString != expectedErrString {
|
||||
t.Errorf("Error string :\n`%s`\ndoes not match expected\n`%s`", errString, expectedErrString)
|
||||
}
|
||||
assert.EqualError(t, ValidateAgainstSchema(chrt, vals), expectedErrString)
|
||||
}
|
||||
|
||||
func TestValidateAgainstSchema2020(t *testing.T) {
|
||||
@@ -207,9 +168,7 @@ func TestValidateAgainstSchema2020(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if err := ValidateAgainstSchema(chrt, vals); err != nil {
|
||||
t.Errorf("Error validating Values against Schema: %s", err)
|
||||
}
|
||||
assert.NoErrorf(t, ValidateAgainstSchema(chrt, vals), "Error validating Values against Schema")
|
||||
}
|
||||
|
||||
func TestValidateAgainstSchema2020Negative(t *testing.T) {
|
||||
@@ -234,20 +193,11 @@ func TestValidateAgainstSchema2020Negative(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
var errString string
|
||||
if err := ValidateAgainstSchema(chrt, vals); err == nil {
|
||||
t.Fatal("Expected an error, but got nil")
|
||||
} else {
|
||||
errString = err.Error()
|
||||
}
|
||||
|
||||
expectedErrString := `subchart:
|
||||
- at '/data': no items match contains schema
|
||||
- at '/data/0': got number, want string
|
||||
`
|
||||
if errString != expectedErrString {
|
||||
t.Errorf("Error string :\n`%s`\ndoes not match expected\n`%s`", errString, expectedErrString)
|
||||
}
|
||||
assert.EqualError(t, ValidateAgainstSchema(chrt, vals), expectedErrString)
|
||||
}
|
||||
|
||||
func TestHTTPURLLoader_Load(t *testing.T) {
|
||||
@@ -262,12 +212,8 @@ func TestHTTPURLLoader_Load(t *testing.T) {
|
||||
|
||||
loader := newHTTPURLLoader()
|
||||
result, err := loader.Load(server.URL)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no error, got: %v", err)
|
||||
}
|
||||
if result == nil {
|
||||
t.Fatal("Expected result to be non-nil")
|
||||
}
|
||||
require.NoError(t, err, "Expected no error, got")
|
||||
require.NotNil(t, result, "Expected result to be non-nil")
|
||||
})
|
||||
|
||||
t.Run("HTTP error status", func(t *testing.T) {
|
||||
@@ -278,12 +224,8 @@ func TestHTTPURLLoader_Load(t *testing.T) {
|
||||
|
||||
loader := newHTTPURLLoader()
|
||||
_, err := loader.Load(server.URL)
|
||||
if err == nil {
|
||||
t.Fatal("Expected error for HTTP 404")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "404") {
|
||||
t.Errorf("Expected error message to contain '404', got: %v", err)
|
||||
}
|
||||
require.Error(t, err, "Expected error for HTTP 404")
|
||||
assert.ErrorContains(t, err, "404", "Expected error message to contain '404'")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -295,9 +237,7 @@ func TestValidateAgainstSingleSchema_UnresolvedURN_Ignored(t *testing.T) {
|
||||
"$ref": "urn:example:helm:schemas:v1:helm-schema-validation-conditions:v1/helmSchemaValidation-true"
|
||||
}`)
|
||||
vals := map[string]any{"any": "value"}
|
||||
if err := ValidateAgainstSingleSchema(vals, schema); err != nil {
|
||||
t.Fatalf("expected no error when URN unresolved is ignored, got: %v", err)
|
||||
}
|
||||
require.NoErrorf(t, ValidateAgainstSingleSchema(vals, schema), "expected no error when URN unresolved is ignored, got")
|
||||
}
|
||||
|
||||
// Non-regression tests for https://github.com/helm/helm/issues/31202
|
||||
@@ -323,14 +263,10 @@ func TestValidateAgainstSchema_MissingSubchartValues_NoPanic(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("ValidateAgainstSchema panicked (missing subchart values): %v", r)
|
||||
}
|
||||
require.Nilf(t, recover(), "ValidateAgainstSchema panicked (missing subchart values)")
|
||||
}()
|
||||
|
||||
if err := ValidateAgainstSchema(chrt, vals); err != nil {
|
||||
t.Fatalf("expected no error when subchart values are missing, got: %v", err)
|
||||
}
|
||||
require.NoErrorf(t, ValidateAgainstSchema(chrt, vals), "expected no error when subchart values are missing, got")
|
||||
}
|
||||
|
||||
func TestValidateAgainstSchema_SubchartNil_NoPanic(t *testing.T) {
|
||||
@@ -351,14 +287,10 @@ func TestValidateAgainstSchema_SubchartNil_NoPanic(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("ValidateAgainstSchema panicked (nil subchart values): %v", r)
|
||||
}
|
||||
require.Nilf(t, recover(), "ValidateAgainstSchema panicked (nil subchart values)")
|
||||
}()
|
||||
|
||||
if err := ValidateAgainstSchema(chrt, vals); err != nil {
|
||||
t.Fatalf("expected no error when subchart values are nil, got: %v", err)
|
||||
}
|
||||
require.NoErrorf(t, ValidateAgainstSchema(chrt, vals), "expected no error when subchart values are nil, got")
|
||||
}
|
||||
|
||||
func TestValidateAgainstSchema_InvalidSubchartValuesType_NoPanic(t *testing.T) {
|
||||
@@ -379,13 +311,9 @@ func TestValidateAgainstSchema_InvalidSubchartValuesType_NoPanic(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("ValidateAgainstSchema panicked (invalid subchart values type): %v", r)
|
||||
}
|
||||
require.Nilf(t, recover(), "ValidateAgainstSchema panicked (invalid subchart values type)")
|
||||
}()
|
||||
|
||||
// We expect a non-nil error (invalid type), but crucially no panic.
|
||||
if err := ValidateAgainstSchema(chrt, vals); err == nil {
|
||||
t.Fatal("expected an error when subchart values have invalid type, got nil")
|
||||
}
|
||||
require.Error(t, ValidateAgainstSchema(chrt, vals), "expected an error when subchart values have invalid type, got nil")
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
chart "helm.sh/helm/v4/pkg/chart/v2"
|
||||
"helm.sh/helm/v4/pkg/release/common"
|
||||
release "helm.sh/helm/v4/pkg/release/v1"
|
||||
@@ -44,9 +46,7 @@ func checkFileCompletion(t *testing.T, cmdName string, shouldBePerformed bool) {
|
||||
|
||||
testcmd := fmt.Sprintf("__complete %s ''", cmdName)
|
||||
_, out, err := executeActionCommandC(storage, testcmd)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error, %s", err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
if !strings.Contains(out, "ShellCompDirectiveNoFileComp") != shouldBePerformed {
|
||||
if shouldBePerformed {
|
||||
t.Errorf("Unexpected directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)
|
||||
|
||||
Reference in New Issue
Block a user