| 861 | } |
| 862 | |
| 863 | func TestAlterFuncMap_require(t *testing.T) { |
| 864 | modTime := time.Now() |
| 865 | c := &chart.Chart{ |
| 866 | Metadata: &chart.Metadata{Name: "conan"}, |
| 867 | Templates: []*common.File{ |
| 868 | {Name: "templates/quote", ModTime: modTime, Data: []byte(`All your base are belong to {{ required "A valid 'who' is required" .Values.who }}`)}, |
| 869 | {Name: "templates/bases", ModTime: modTime, Data: []byte(`All {{ required "A valid 'bases' is required" .Values.bases }} of them!`)}, |
| 870 | }, |
| 871 | } |
| 872 | |
| 873 | v := common.Values{ |
| 874 | "Values": common.Values{ |
| 875 | "who": "us", |
| 876 | "bases": 2, |
| 877 | }, |
| 878 | "Chart": c.Metadata, |
| 879 | "Release": common.Values{ |
| 880 | "Name": "That 90s meme", |
| 881 | }, |
| 882 | } |
| 883 | |
| 884 | out, err := Render(c, v) |
| 885 | if err != nil { |
| 886 | t.Fatal(err) |
| 887 | } |
| 888 | |
| 889 | expectStr := "All your base are belong to us" |
| 890 | if gotStr := out["conan/templates/quote"]; gotStr != expectStr { |
| 891 | t.Errorf("Expected %q, got %q (%v)", expectStr, gotStr, out) |
| 892 | } |
| 893 | expectNum := "All 2 of them!" |
| 894 | if gotNum := out["conan/templates/bases"]; gotNum != expectNum { |
| 895 | t.Errorf("Expected %q, got %q (%v)", expectNum, gotNum, out) |
| 896 | } |
| 897 | |
| 898 | // test required without passing in needed values with lint mode on |
| 899 | // verifies lint replaces required with an empty string (should not fail) |
| 900 | lintValues := common.Values{ |
| 901 | "Values": common.Values{ |
| 902 | "who": "us", |
| 903 | }, |
| 904 | "Chart": c.Metadata, |
| 905 | "Release": common.Values{ |
| 906 | "Name": "That 90s meme", |
| 907 | }, |
| 908 | } |
| 909 | var e Engine |
| 910 | e.LintMode = true |
| 911 | out, err = e.Render(c, lintValues) |
| 912 | if err != nil { |
| 913 | t.Fatal(err) |
| 914 | } |
| 915 | |
| 916 | expectStr = "All your base are belong to us" |
| 917 | if gotStr := out["conan/templates/quote"]; gotStr != expectStr { |
| 918 | t.Errorf("Expected %q, got %q (%v)", expectStr, gotStr, out) |
| 919 | } |
| 920 | expectNum = "All of them!" |