From 431c0231384c4f1de23d315549057c1d650f3a02 Mon Sep 17 00:00:00 2001 From: S3B4SZ17 Date: Sat, 9 Mar 2024 21:08:22 -0600 Subject: [PATCH] feat #257 Miscellaneous updates * Adding a Makefile for simplicity to build the project and clean it, also to run the tests more easily * Updated the fakeserver so we can test the new func for non JSON responses --- Makefile | 25 +++++++++++++++++++++++++ fakeserver/fakeserver.go | 18 ++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..88c31e24 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +# Change these variables as necessary. +MAIN_PACKAGE_PATH := ./ +BINARY_NAME := terraform-provider-restapi +GO := go +GO_VERSION ?= 1.21 + +# ==================================================================================== # +# DEVELOPMENT +# ==================================================================================== # + +## test: run all tests +.PHONY: test +test: + bash ./scripts/set-local-testing.rc + bash ./scripts/test.sh + +## build: build the application +.PHONY: build +build: + # Include additional build steps compilation here... + $(GO) build -o=${BINARY_NAME}.o ${MAIN_PACKAGE_PATH} + +.PHONY: clean +clean : + rm ${BINARY_NAME}.o diff --git a/fakeserver/fakeserver.go b/fakeserver/fakeserver.go index 8a16a3d5..f22fa366 100644 --- a/fakeserver/fakeserver.go +++ b/fakeserver/fakeserver.go @@ -212,10 +212,20 @@ func (svr *Fakeserver) handleAPIObject(w http.ResponseWriter, r *http.Request) { } svr.objects[id] = obj - /* Coax the data we were sent back to JSON and send it to the user */ - b, _ := json.Marshal(obj) - w.Write(b) - return + /* Edge case to test a response from the server as not a JSON object */ + if val, ok := obj["No_json"]; ok { + if val == true { + log.Printf("fakeserver.go: Returning a non-JSON response\n") + b, _ := json.Marshal(obj["Id"]) + w.Write(b) + return + } + } else { + /* Coax the data we were sent back to JSON and send it to the user */ + b, _ := json.Marshal(obj) + w.Write(b) + return + } } /* No data was sent... must be just a retrieval */ if svr.debug {