git_repo_handler_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package api_test
  2. // import (
  3. // "encoding/json"
  4. // "net/http"
  5. // "strings"
  6. // "testing"
  7. // "github.com/porter-dev/porter/internal/kubernetes"
  8. // )
  9. // // ------------------------- TEST TYPES AND MAIN LOOP ------------------------- //
  10. // type reposTest struct {
  11. // initializers []func(tester *tester)
  12. // msg string
  13. // method string
  14. // endpoint string
  15. // body string
  16. // expStatus int
  17. // expBody string
  18. // useCookie bool
  19. // validators []func(c *reposTest, tester *tester, t *testing.T)
  20. // }
  21. // func testReposRequests(t *testing.T, tests []*reposTest, canQuery bool) {
  22. // for _, c := range tests {
  23. // // create a new tester
  24. // tester := newTester(canQuery)
  25. // // if there's an initializer, call it
  26. // for _, init := range c.initializers {
  27. // init(tester)
  28. // }
  29. // req, err := http.NewRequest(
  30. // c.method,
  31. // c.endpoint,
  32. // strings.NewReader(c.body),
  33. // )
  34. // tester.req = req
  35. // if c.useCookie {
  36. // req.AddCookie(tester.cookie)
  37. // }
  38. // if err != nil {
  39. // t.Fatal(err)
  40. // }
  41. // tester.execute()
  42. // rr := tester.rr
  43. // // first, check that the status matches
  44. // if status := rr.Code; status != c.expStatus {
  45. // t.Errorf("%s, handler returned wrong status code: got %v want %v",
  46. // c.msg, status, c.expStatus)
  47. // }
  48. // // if there's a validator, call it
  49. // for _, validate := range c.validators {
  50. // validate(c, tester, t)
  51. // }
  52. // }
  53. // }
  54. // // ------------------------- TEST FIXTURES AND FUNCTIONS ------------------------- //
  55. // // var listReposTests = []*reposTest{
  56. // // &reposTest{
  57. // // initializers: []func(tester *tester){
  58. // // initDefaultRepos,
  59. // // },
  60. // // msg: "List repos",
  61. // // method: "GET",
  62. // // endpoint: "/api/repos/github/porter/master/contents?dir=" + url.QueryEscape("./"),
  63. // // body: "",
  64. // // expStatus: http.StatusOK,
  65. // // expBody: "unimplemented",
  66. // // useCookie: true,
  67. // // validators: []func(c *reposTest, tester *tester, t *testing.T){
  68. // // reposListValidator,
  69. // // },
  70. // // },
  71. // // }
  72. // // func TestHandleListRepos(t *testing.T) {
  73. // // testReposRequests(t, listReposTests, true)
  74. // // }
  75. // // ------------------------- INITIALIZERS AND VALIDATORS ------------------------- //
  76. // func initDefaultRepos(tester *tester) {
  77. // initUserDefault(tester)
  78. // agent := kubernetes.GetAgentTesting(defaultObjects...)
  79. // // overwrite the test agent with new resources
  80. // tester.app.TestAgents.K8sAgent = agent
  81. // }
  82. // func reposListValidator(c *reposTest, tester *tester, t *testing.T) {
  83. // var gotBody map[string]interface{}
  84. // var expBody map[string]interface{}
  85. // json.Unmarshal(tester.rr.Body.Bytes(), &gotBody)
  86. // json.Unmarshal([]byte(c.expBody), &expBody)
  87. // if string(tester.rr.Body.Bytes()) != c.expBody {
  88. // t.Errorf("Mismatch")
  89. // }
  90. // }