Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/config/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Endpoint struct {
RegionName string
}

// TODO: clean up after PR#138 is merged and tested https://github.com/GoogleCloudPlatform/gcping/pull/138
// EndpointsFromServer is used by the cli to generate an Endpoint map
// using json served by the gcping endpoints.
func EndpointsFromServer(ctx context.Context, endpointsURL string) (map[string]Endpoint, error) {
Expand Down
13 changes: 0 additions & 13 deletions internal/httphandler/httphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package httphandler

import (
"encoding/json"
"fmt"
"net/http"
"sync"
Expand Down Expand Up @@ -49,9 +48,6 @@ func New(opts *Options) *Handler {
mux := http.NewServeMux()
mux.HandleFunc("/", s.StaticHandler())

// TODO: clean up after PR#138 is merged and tested https://github.com/GoogleCloudPlatform/gcping/pull/138
mux.HandleFunc("/api/endpoints", s.HandleEndpoints)

mux.HandleFunc("/api/ping", s.HandlePing)

// Serve /ping with region response to fix issue#96 on older cli versions.
Expand All @@ -75,15 +71,6 @@ func (s *Handler) StaticHandler() http.HandlerFunc {
}
}

// HandleEndpoints returns a list of available endpoints as JSON.
func (s *Handler) HandleEndpoints(w http.ResponseWriter, r *http.Request) {
addHeaders(w)
w.Header().Add("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(s.Endpoints); err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
}

// HandlePing returns the current region as a response for ping.
func (s *Handler) HandlePing(w http.ResponseWriter, r *http.Request) {
addHeaders(w)
Expand Down
35 changes: 0 additions & 35 deletions internal/httphandler/httphandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package httphandler

import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -26,39 +25,6 @@ import (
"github.com/google/go-cmp/cmp"
)

func TestEndpoints(t *testing.T) {
t.Parallel()

handler := New(&Options{Endpoints: config.AllEndpoints})
req := httptest.NewRequest(http.MethodGet, "https://gcping.com/api/endpoints", nil)
w := httptest.NewRecorder()
handler.HandleEndpoints(w, req)
resp := w.Result()
t.Cleanup(func() { resp.Body.Close() })
wantHeader := http.Header{
"Content-Type": {"application/json"},
"Cache-Control": {"no-store"},
"Access-Control-Allow-Origin": {"*"},
"Strict-Transport-Security": {"max-age=3600; includeSubdomains; preload"},
}

if got, want := resp.StatusCode, http.StatusOK; got != want {
t.Errorf("HandleEndpoints() Status Code: got %v, want %v", got, want)
}
if diff := cmp.Diff(wantHeader, resp.Header); diff != "" {
t.Errorf("HandleEndpoiints() Header (-want, +got):\n%s", diff)
}

var got map[string]config.Endpoint
err := json.NewDecoder(resp.Body).Decode(&got)
if err != nil {
t.Errorf("Failed to decode JSON: %v", err)
}
if diff := cmp.Diff(config.AllEndpoints, got); diff != "" {
t.Errorf("HandleEndpoints() = (-want, +got):\n%s", diff)
}
}

func TestPing(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -146,7 +112,6 @@ func TestRouting(t *testing.T) {
{"/index.html", http.StatusOK, "<html></html>"},
{"/api", http.StatusNotFound, "404 page not found\n"},
{"/api/ping", http.StatusOK, "test-region\n"},
{"/api/endpoints", http.StatusOK, `{"test-region":{"URL":"https://test-region","Region":"test-region","RegionName":"Test Region"}}` + "\n"},
{"/ping", http.StatusOK, "test-region\n"},
}
for _, tc := range testCases {
Expand Down