test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. Config: map[string]string{
  58. "group": "apps",
  59. "version": "v1",
  60. "resource": "deployments",
  61. },
  62. },
  63. Name: "crd",
  64. Label: "CRDs",
  65. Sections: []*models.FormSection{
  66. &models.FormSection{
  67. Name: "section_one",
  68. Contents: []*models.FormContent{
  69. &models.FormContent{
  70. Type: "resourcelist",
  71. Value: `[{"name": "certificate_1","namespace": "default","status": "Ready" },{"name": "certificate_2","namespace": "default","status": "Issuing" }]`,
  72. },
  73. },
  74. },
  75. },
  76. },
  77. },
  78. }
  79. bytes, err := json.Marshal(form)
  80. if err != nil {
  81. red := color.New(color.FgRed)
  82. red.Println("Error running test:", err.Error())
  83. os.Exit(1)
  84. }
  85. fmt.Println(string(bytes))
  86. },
  87. }
  88. func init() {
  89. rootCmd.AddCommand(testCmd)
  90. }
  91. // // FormSection is a section of a form
  92. // type FormSection struct {
  93. // Context *FormContext `yaml:"context" json:"context"`
  94. // Name string `yaml:"name" json:"name"`
  95. // ShowIf string `yaml:"show_if" json:"show_if"`
  96. // Contents []*FormContent `yaml:"contents" json:"contents,omitempty"`
  97. // }
  98. // // FormContent is a form's atomic unit
  99. // type FormContent struct {
  100. // Context *FormContext `yaml:"context" json:"context"`
  101. // Type string `yaml:"type" json:"type"`
  102. // Label string `yaml:"label" json:"label"`
  103. // Name string `yaml:"name,omitempty" json:"name,omitempty"`
  104. // Value interface{} `yaml:"value,omitempty" json:"value,omitempty"`
  105. // Settings struct {
  106. // Default interface{} `yaml:"default,omitempty" json:"default,omitempty"`
  107. // Unit interface{} `yaml:"unit,omitempty" json:"unit,omitempty"`
  108. // } `yaml:"settings,omitempty" json:"settings,omitempty"`
  109. // }