Skip to content

Commit

Permalink
fix(pingEndpoint): change build type to 'oss2', use correct version (#…
Browse files Browse the repository at this point in the history
…21723)



Signed-off-by: Jakub Bednar <jakub.bednar@gmail.com>
  • Loading branch information
bednar authored Jun 24, 2021
1 parent 156e55a commit 6aae544
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion http/legacy/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type HandlerConfig struct {
}

func NewHandlerConfig() *HandlerConfig {
return &HandlerConfig{}
return &HandlerConfig{Version: influxdb.GetBuildInfo().Version}
}

// Opts returns the CLI options for use with kit/cli.
Expand Down
2 changes: 1 addition & 1 deletion http/legacy/influxqld_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestInfluxQLdHandler_HandleQuery(t *testing.T) {
InfluxqldQueryService: tt.fields.ProxyQueryService,
}

h := NewInfluxQLHandler(b, HandlerConfig{})
h := NewInfluxQLHandler(b, *NewHandlerConfig())
h.Logger = zaptest.NewLogger(t)

if tt.context != nil {
Expand Down
60 changes: 60 additions & 0 deletions http/legacy/ping_handle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package legacy

import (
"net/http"
"net/http/httptest"
"testing"
)

func TestPingHandler(t *testing.T) {
type wants struct {
statusCode int
version string
build string
}
tests := []struct {
name string
w *httptest.ResponseRecorder
r *http.Request
wants wants
}{
{
name: "GET request",
w: httptest.NewRecorder(),
r: httptest.NewRequest(http.MethodGet, "/ping", nil),
wants: wants{
statusCode: http.StatusNoContent,
version: "2.0.0",
build: "oss2",
},
},
{
name: "HEAD request",
w: httptest.NewRecorder(),
r: httptest.NewRequest(http.MethodHead, "/ping", nil),
wants: wants{
statusCode: http.StatusNoContent,
version: "2.0.0",
build: "oss2",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
NewPingHandler("2.0.0").pingHandler(tt.w, tt.r)
res := tt.w.Result()
build := res.Header.Get("X-Influxdb-Build")
version := res.Header.Get("X-Influxdb-Version")

if res.StatusCode != tt.wants.statusCode {
t.Errorf("%q. PingHandler() = %v, want %v", tt.name, res.StatusCode, tt.wants.statusCode)
}
if build != tt.wants.build {
t.Errorf("%q. PingHandler() = %v, want %v", tt.name, build, tt.wants.build)
}
if version != tt.wants.version {
t.Errorf("%q. PingHandler() = %v, want %v", tt.name, version, tt.wants.version)
}
})
}
}
2 changes: 1 addition & 1 deletion http/legacy/ping_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewPingHandler(version string) *PingHandler {

// handlePostLegacyWrite is the HTTP handler for the POST /write route.
func (h *PingHandler) pingHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-Influxdb-Build", "cloud2")
w.Header().Add("X-Influxdb-Build", "oss2")
w.Header().Add("X-Influxdb-Version", h.InfluxDBVersion)
w.WriteHeader(http.StatusNoContent)
}
2 changes: 1 addition & 1 deletion http/platform_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewPlatformHandler(b *APIBackend, opts ...APIHandlerOptFn) *PlatformHandler
wrappedHandler = kithttp.SkipOptions(wrappedHandler)

legacyBackend := newLegacyBackend(b)
lh := newLegacyHandler(legacyBackend, legacy.HandlerConfig{})
lh := newLegacyHandler(legacyBackend, *legacy.NewHandlerConfig())

return &PlatformHandler{
AssetHandler: assetHandler,
Expand Down

0 comments on commit 6aae544

Please sign in to comment.