(t *testing.T)
| 106 | } |
| 107 | |
| 108 | func startTransportE2EHTTPUpstream(t *testing.T) *httptest.Server { |
| 109 | t.Helper() |
| 110 | |
| 111 | mux := http.NewServeMux() |
| 112 | mux.HandleFunc("/rest/tasks/", func(w http.ResponseWriter, r *http.Request) { |
| 113 | if got := r.Header.Get("Authorization"); got != "Bearer owner-token" { |
| 114 | http.Error(w, "missing credential authorization", http.StatusUnauthorized) |
| 115 | return |
| 116 | } |
| 117 | transportE2EWriteJSON(w, map[string]interface{}{ |
| 118 | "transport": "rest", |
| 119 | "authorization": r.Header.Get("Authorization"), |
| 120 | "task_gid": strings.TrimPrefix(r.URL.Path, "/rest/tasks/"), |
| 121 | "opt_fields": r.URL.Query().Get("opt_fields"), |
| 122 | }) |
| 123 | }) |
| 124 | mux.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) { |
| 125 | if got := r.Header.Get("Authorization"); got != "Bearer owner-token" { |
| 126 | http.Error(w, "missing credential authorization", http.StatusUnauthorized) |
| 127 | return |
| 128 | } |
| 129 | var body map[string]interface{} |
| 130 | if err := json.NewDecoder(r.Body).Decode(&body); err != nil { |
| 131 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 132 | return |
| 133 | } |
| 134 | variables, _ := body["variables"].(map[string]interface{}) |
| 135 | transportE2EWriteJSON(w, map[string]interface{}{ |
| 136 | "transport": "graphql", |
| 137 | "authorization": r.Header.Get("Authorization"), |
| 138 | "operationName": body["operationName"], |
| 139 | "variables": variables, |
| 140 | "data": map[string]interface{}{ |
| 141 | "issues": map[string]interface{}{ |
| 142 | "nodes": []map[string]interface{}{{"id": "ISS-1", "title": fmt.Sprintf("%v-%v", variables["after"], variables["first"])}}, |
| 143 | }, |
| 144 | }, |
| 145 | }) |
| 146 | }) |
| 147 | mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { |
| 148 | if got := r.Header.Get("Authorization"); got != "Bearer owner-token" { |
| 149 | http.Error(w, "missing credential authorization", http.StatusUnauthorized) |
| 150 | return |
| 151 | } |
| 152 | conn, err := (&websocket.Upgrader{}).Upgrade(w, r, nil) |
| 153 | if err != nil { |
| 154 | return |
| 155 | } |
| 156 | defer conn.Close() |
| 157 | var message map[string]interface{} |
| 158 | if err := conn.ReadJSON(&message); err != nil { |
| 159 | return |
| 160 | } |
| 161 | _ = conn.WriteJSON(map[string]interface{}{ |
| 162 | "transport": "websocket", |
| 163 | "authorization": r.Header.Get("Authorization"), |
| 164 | "query": message["query"], |
| 165 | }) |
no test coverage detected