test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package cmd
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. "github.com/fatih/color"
  7. "github.com/porter-dev/porter/internal/models"
  8. "github.com/spf13/cobra"
  9. )
  10. var testCmd = &cobra.Command{
  11. Use: "test",
  12. Short: "Testing",
  13. Run: func(cmd *cobra.Command, args []string) {
  14. // chart, err := loader.LoadChart("https://porter-dev.github.io/chart-repo", "docker", "0.0.1")
  15. // if err != nil {
  16. // red := color.New(color.FgRed)
  17. // red.Println("Error running test:", err.Error())
  18. // os.Exit(1)
  19. // }
  20. // bytes, err := yaml.Marshal(chart)
  21. // if err != nil {
  22. // red := color.New(color.FgRed)
  23. // red.Println("Error running test:", err.Error())
  24. // os.Exit(1)
  25. // }
  26. // fmt.Println(string(bytes))
  27. form := &models.FormYAML{
  28. Tabs: []*models.FormTab{
  29. &models.FormTab{
  30. Context: &models.FormContext{
  31. Type: "helm/values",
  32. },
  33. Name: "main",
  34. Label: "Main Settings",
  35. Sections: []*models.FormSection{
  36. &models.FormSection{
  37. Name: "section_one",
  38. Contents: []*models.FormContent{
  39. &models.FormContent{
  40. Type: "number-input",
  41. Value: "service.targetPort",
  42. Label: "Target Port",
  43. Settings: struct {
  44. Default interface{} `yaml:"default,omitempty" json:"default,omitempty"`
  45. Unit interface{} `yaml:"unit,omitempty" json:"unit,omitempty"`
  46. }{
  47. Default: 8000,
  48. },
  49. },
  50. },
  51. },
  52. },
  53. },
  54. &models.FormTab{
  55. Context: &models.FormContext{
  56. Type: "cluster",
  57. },
  58. Name: "crd",
  59. Label: "CRDs",
  60. Sections: []*models.FormSection{
  61. &models.FormSection{
  62. Name: "section_one",
  63. Contents: []*models.FormContent{
  64. &models.FormContent{
  65. Type: "resourcelist",
  66. Value: `[{"name": "resource_1"}]`,
  67. },
  68. },
  69. },
  70. },
  71. },
  72. },
  73. }
  74. bytes, err := json.Marshal(form)
  75. if err != nil {
  76. red := color.New(color.FgRed)
  77. red.Println("Error running test:", err.Error())
  78. os.Exit(1)
  79. }
  80. fmt.Println(string(bytes))
  81. },
  82. }
  83. func init() {
  84. rootCmd.AddCommand(testCmd)
  85. }
  86. // // FormSection is a section of a form
  87. // type FormSection struct {
  88. // Context *FormContext `yaml:"context" json:"context"`
  89. // Name string `yaml:"name" json:"name"`
  90. // ShowIf string `yaml:"show_if" json:"show_if"`
  91. // Contents []*FormContent `yaml:"contents" json:"contents,omitempty"`
  92. // }
  93. // // FormContent is a form's atomic unit
  94. // type FormContent struct {
  95. // Context *FormContext `yaml:"context" json:"context"`
  96. // Type string `yaml:"type" json:"type"`
  97. // Label string `yaml:"label" json:"label"`
  98. // Name string `yaml:"name,omitempty" json:"name,omitempty"`
  99. // Value interface{} `yaml:"value,omitempty" json:"value,omitempty"`
  100. // Settings struct {
  101. // Default interface{} `yaml:"default,omitempty" json:"default,omitempty"`
  102. // Unit interface{} `yaml:"unit,omitempty" json:"unit,omitempty"`
  103. // } `yaml:"settings,omitempty" json:"settings,omitempty"`
  104. // }