Skip to content

Commit

Permalink
feat Mastercard#257 Miscellaneous updates
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
S3B4SZ17 committed Mar 10, 2024
1 parent f5fda96 commit 431c023
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
18 changes: 14 additions & 4 deletions fakeserver/fakeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 431c023

Please sign in to comment.