Skip to content

Commit

Permalink
chore: remove unnecessary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karel-rehor committed Sep 27, 2024
1 parent b136f75 commit 5ab7992
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 82 deletions.
35 changes: 0 additions & 35 deletions influxdb3/client_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
package influxdb3_test

import (
"bytes"
"context"
"fmt"
"log/slog"
"os"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -364,35 +361,3 @@ func TestEscapedStringValues(t *testing.T) {
assert.EqualValues(t, "escaped\\nline and space", qit.Value()["tag2"])
}
}

func TestRespBodyClosedAfterError(t *testing.T) {
SkipCheck(t)
url := os.Getenv("TESTING_INFLUXDB_URL")
token := os.Getenv("TESTING_INFLUXDB_TOKEN")
database := os.Getenv("TESTING_INFLUXDB_DATABASE")

buffer := bytes.NewBuffer(make([]byte, 256))
logger := slog.New(slog.NewTextHandler(buffer, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))
origLogger := slog.Default()
slog.SetDefault(logger)
defer func() {
b := bytes.Trim(buffer.Bytes(), "\x00")
logged := strings.Split(string(b), "\n")
assert.Regexp(t,
".*level=DEBUG msg=\"Closed response body on HTTP Error\\(invalid: no data written, errors encountered on line\\(s\\): line 1: No fields were provided\\)\"",
logged[0])
slog.SetLogLoggerLevel(slog.LevelInfo)
slog.SetDefault(origLogger)
}()

client, err := influxdb3.New(influxdb3.ClientConfig{
Host: url,
Token: token,
Database: database,
})

err = client.Write(context.Background(), []byte("test,type=negative val="))
require.Error(t, err)
}
47 changes: 0 additions & 47 deletions influxdb3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
package influxdb3

import (
"bytes"
"context"
"fmt"
"log/slog"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -626,47 +623,3 @@ func TestFixUrl(t *testing.T) {
})
}
}

func TestRespCloseOnError(t *testing.T) {
slog.SetLogLoggerLevel(slog.LevelDebug)
buffer := bytes.NewBuffer(make([]byte, 256))
logger := slog.New(slog.NewTextHandler(buffer, &slog.HandlerOptions{
Level: slog.LevelDebug,
}))
origLogger := slog.Default()
slog.SetDefault(logger)
defer func() {
b := bytes.Trim(buffer.Bytes(), "\x00")
logged := strings.Split(string(b), "\n")
assert.Regexp(t,
".*level=DEBUG msg=\"Closed response body on HTTP Error\\(Not Found: The page you are looking for was not found\\).*",
logged[0])
slog.SetLogLoggerLevel(slog.LevelInfo)
slog.SetDefault(origLogger)
}()
msg := "{ \"code\": \"Not Found\", \"message\": \"The page you are looking for was not found\", \"data\": null }"
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
_, _ = w.Write([]byte(msg))
}))
defer ts.Close()
client, err := New(ClientConfig{Host: ts.URL, Token: "my-token"})
require.NoError(t, err)
turl, err := url.Parse(ts.URL)
require.NoError(t, err)
res, callErr := client.makeAPICall(context.Background(), httpParams{ //nolint:bodyclose
endpointURL: turl,
queryParams: nil,
httpMethod: "GET",
headers: nil,
body: nil,
})

if callErr != nil {
slog.Info(callErr.Error())
assert.EqualValues(t, "Not Found: The page you are looking for was not found", callErr.Error())
} else {
assert.Fail(t, fmt.Sprintf("Call should have returned error. But got res %s", res.Body))
}
}

0 comments on commit 5ab7992

Please sign in to comment.