Skip to content

Commit

Permalink
Fixed test setup bug and deprecations.
Browse files Browse the repository at this point in the history
  • Loading branch information
GollyTicker committed Oct 4, 2023
1 parent 93f878a commit a29a9a0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
16 changes: 8 additions & 8 deletions src/httpRequest.go
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httputil"
"os"
Expand Down Expand Up @@ -45,7 +45,7 @@ func invokeInternalHttpRequest(requestBinary []byte) ([]byte, string) {
PanicWithMessageOnError(err, func() string { return "Failed internal HTTP request. Error: " + err.Error() })
defer func() { _ = httpResponse.Body.Close() }()

body, err := ioutil.ReadAll(httpResponse.Body)
body, err := io.ReadAll(httpResponse.Body)
PanicOnError(err)

headers, err := httputil.DumpResponse(httpResponse, false)
Expand All @@ -66,12 +66,12 @@ func invokeCurlRequest(requestBinary []byte, curlPath string) ([]byte, string) {
fmt.Println("Invoking curl http request.")
}

tmpDir, err := ioutil.TempDir(os.TempDir(), "protocurl-temp-*")
tmpDir, err := os.MkdirTemp(os.TempDir(), "protocurl-temp-*")
PanicOnError(err)
defer func() { _ = os.RemoveAll(tmpDir) }()

requestBinaryFile := filepath.Join(tmpDir, "request.bin")
err = ioutil.WriteFile(requestBinaryFile, requestBinary, publicReadPermissions)
err = os.WriteFile(requestBinaryFile, requestBinary, publicReadPermissions)
PanicOnError(err)

responseBinaryFile := filepath.Join(tmpDir, "response.bin")
Expand Down Expand Up @@ -118,17 +118,17 @@ func invokeCurlRequest(requestBinary []byte, curlPath string) ([]byte, string) {
err = curlCmd.Run()

if !CurrentConfig.ShowOutputOnly && curlStdOut.Len() != 0 {
fmt.Printf("%s CURL Output %s\n%s\n", VISUAL_SEPARATOR, VISUAL_SEPARATOR, string(curlStdOut.Bytes()))
fmt.Printf("%s CURL Output %s\n%s\n", VISUAL_SEPARATOR, VISUAL_SEPARATOR, curlStdOut.String())
}

if !CurrentConfig.ShowOutputOnly && curlStdErr.Len() != 0 {
fmt.Printf("%s CURL ERROR %s\n%s\n", VISUAL_SEPARATOR, VISUAL_SEPARATOR, string(curlStdErr.Bytes()))
fmt.Printf("%s CURL ERROR %s\n%s\n", VISUAL_SEPARATOR, VISUAL_SEPARATOR, curlStdErr.String())
}

PanicWithMessageOnError(err, func() string { return "Encountered an error while running curl. Error: " + err.Error() })

responseBinary, err := ioutil.ReadFile(responseBinaryFile)
responseHeaders, err := ioutil.ReadFile(responseHeadersTextFile)
responseBinary, err := os.ReadFile(responseBinaryFile)
responseHeaders, err := os.ReadFile(responseHeadersTextFile)
responseHeadersText := strings.TrimSpace(string(responseHeaders))

ensureStatusCodeIs2XX(responseHeadersText)
Expand Down
5 changes: 2 additions & 3 deletions src/protoRegistry.go
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -46,7 +45,7 @@ func convertProtoFilesToProtoRegistryFiles() *protoregistry.Files {

protocPath, isBundled := findProtocExecutable()

tmpDir, errTmp := ioutil.TempDir(os.TempDir(), "protocurl-temp-*")
tmpDir, errTmp := os.MkdirTemp(os.TempDir(), "protocurl-temp-*")
PanicOnError(errTmp)
defer func() { _ = os.RemoveAll(tmpDir) }()

Expand Down Expand Up @@ -85,7 +84,7 @@ func convertProtoFilesToProtoRegistryFiles() *protoregistry.Files {
_, _ = fmt.Fprintln(os.Stderr, "Encountered errors while attempting to "+actionDescription+" via protoc:\n"+protocErr.String())
}

inputFileBin, err := ioutil.ReadFile(inputFileBinPath)
inputFileBin, err := os.ReadFile(inputFileBinPath)
PanicOnError(err)

protoFileDescriptorSet := descriptorpb.FileDescriptorSet{}
Expand Down
Expand Up @@ -5,6 +5,8 @@ date: {
nanos: 152000000
}
includeReason: true
=========================== GET Response Text =========================== <<<
reason: "Tough luck on Wednesday... 😕"
formattedDate: "Wed, 23 Mar 2022 14:15:39 GMT"
######### STDERR #########
Error: Internal Http implementation doesn't support GET requests with body. Please use curl.
######### EXIT 1 #########
######### EXIT 0 #########
20 changes: 11 additions & 9 deletions test/suite/test.sh
Expand Up @@ -18,10 +18,11 @@ export TESTS_SUCCESS="true"
source test/suite/setup.sh

testSingleRequest() {
FILENAME="$1"
ARGS="$2"
BEFORE_TEST_BASH="$3"
AFTER_TEST_BASH="$4"
# use local variables to avoid collision with other functions
local FILENAME="$1"
local ARGS="$2"
local BEFORE_TEST_BASH="$3"
local AFTER_TEST_BASH="$4"

if [[ "$FILENAME" == "response-type-arg-overidden-decode-raw" && "$(uname)" == *"MINGW"* ]]; then
echo "🚧🚧🚧 SKIPPED 🚧🚧🚧 - Skipping response-type-arg-overidden-decode-raw on Windows due to special circumstances."
Expand Down Expand Up @@ -74,15 +75,16 @@ testSingleRequest() {

# A spec consists of potentially many single requests.
testSingleSpec() {
FILENAME="$1"
ARGS="$2"
BEFORE_TEST_BASH="$3"
AFTER_TEST_BASH="$4"
# use local variables to avoid collision with other functions
local FILENAME="$1"
local ARGS="$2"
local BEFORE_TEST_BASH="$3"
local AFTER_TEST_BASH="$4"

testSingleRequest "$FILENAME" "$ARGS" "$BEFORE_TEST_BASH" "$AFTER_TEST_BASH"
shift 4
for extra_arg in "$@"; do
NEW_FILENAME="${FILENAME}-${extra_arg#--}"
local NEW_FILENAME="${FILENAME}-${extra_arg#--}"
NEW_FILENAME="$(echo "$NEW_FILENAME" | sed 's/ /_/g')" # sanitise filename
testSingleRequest "$NEW_FILENAME" "$extra_arg $ARGS" "$BEFORE_TEST_BASH" "$AFTER_TEST_BASH"
done
Expand Down

0 comments on commit a29a9a0

Please sign in to comment.