Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions cmd/apiServerMain/apiServerMain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,26 @@ import (
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
func main() {

log.Println("Reading config..")


config, err := config.Readconfig("config_app_secrets", "env")
if err != nil {
fmt.Printf("Error: cannot read config: %s", err)
if err != nil {
fmt.Printf("Error: cannot read config: %s", err)
os.Exit(42)
}
}

log.Printf("Config: %s", config.DBUser)

log.Println("Starting up database..")
dataBase, err := models.NewPostgresDb(config.DBUser,
config.DBName,
config.DBPassword,
config.DBSSLmode,
config.DBMaxOpenConns,
config.DBMaxOpenConns)
config.DBName,
config.DBPassword,
config.DBSSLmode,
config.DBMaxOpenConns,
config.DBMaxOpenConns)
if err != nil {
fmt.Printf("Error connecting to database: %s", err)
os.Exit(42)
Expand All @@ -55,9 +53,7 @@ func main() {
}

log.Println("Starting up server..")
port := fmt.Sprintf(":%s", config.APIPort)
port := fmt.Sprintf(":%s", config.APIPort)
server := api.NewAPIServer(port, dataBase)
server.Run(port)

}

6 changes: 2 additions & 4 deletions cmd/paginateTest/paginateTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
)

type test_struct struct {
Test string
Test string
}


func main() {
baseURL := "http://localhost:8969/"
resource := "/services"
Expand All @@ -33,8 +32,7 @@ func main() {
urlStr := fmt.Sprintf("%v", u)

log.Printf("Listing services by using limit & offset to %s", urlStr)
page = page + 1
page = page + 1

}

}
17 changes: 8 additions & 9 deletions cmd/patheticTester/patheticTester.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import (
)

// Declaring Global variables
var baseURL string = "http://localhost:8969/"
var testsPassed int = 0
var testsFailed int = 0
var (
baseURL string = "http://localhost:8969/"
testsPassed int = 0
testsFailed int = 0
)

func scoreGlobalTestsPassedandFailes(testCode, wantedCode int) {
if testCode == wantedCode {
color.Green("Test passed: %d", testCode)
testsPassed ++
testsPassed++
} else {
color.Red("Error!! Wanted %d, but got unexpected status: %d", wantedCode, testCode)
testsFailed ++
testsFailed++
}
}

Expand All @@ -28,8 +30,6 @@ func printTestSeperator(testCategory string) {
}

func main() {


// Run tests
printTestSeperator("testGetHealthendpoint")
testGetHealthendpoint()
Expand All @@ -55,5 +55,4 @@ func main() {
println("\n\n")
color.Red("Tests failed: %s", strconv.Itoa(testsFailed))
color.Green("Tests passed: %s", strconv.Itoa(testsPassed))

}
}
8 changes: 2 additions & 6 deletions cmd/patheticTester/testDeleteServiceById.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/stablecaps/services-api-go/internal/dbtools"
)



func testDeleteserviceById() {
postedServiceData := dbtools.CreateExplicitService(dbtools.MakeRandomName(), dbtools.MakeRandomDescription(4), "v1,v2,v3")

Expand All @@ -18,13 +16,12 @@ func testDeleteserviceById() {
paramMapList := map[string]string{}
resp, _ := dbtools.MakeHttpRequestWrapper(baseURL, fullEndpoint, "DELETE", paramMapList, nil)

scoreGlobalTestsPassedandFailes(resp.StatusCode, 200)
scoreGlobalTestsPassedandFailes(resp.StatusCode, 200)
}

func testDeleteserviceByIdError() {
endpoint := "/services/id/"


testNameSlice := []string{
// Test serviceId 400s
"badServiceId", "outOfRangeServiceId",
Expand All @@ -35,7 +32,6 @@ func testDeleteserviceByIdError() {
paramMapList := map[string]string{}
serviceIdList := []string{"fake", "-10", "99999999"}


for idx, testName := range testNameSlice {
fmt.Println("\n~~~~~~~~~~~~~~~~~~~~")
fmt.Printf("Running test %d: - %s\n", idx, testName)
Expand All @@ -47,4 +43,4 @@ func testDeleteserviceByIdError() {
scoreGlobalTestsPassedandFailes(resp.StatusCode, wantedCodes[idx])

}
}
}
6 changes: 2 additions & 4 deletions cmd/patheticTester/testGetServiceById.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
func testGetServiceById() {
endpoint := "/services/id/"


testNameSlice := []string{
// Test serviceId 400s
"badServiceId", "outOfRangeServiceId",
Expand All @@ -18,8 +17,7 @@ func testGetServiceById() {
}
wantedCodes := []int{404, 404, 200}
paramMapList := map[string]string{}
serviceIdList := []string{"fake", "-10", "5",}

serviceIdList := []string{"fake", "-10", "5"}

for idx, testName := range testNameSlice {
fmt.Println("\n~~~~~~~~~~~~~~~~~~~~")
Expand All @@ -30,4 +28,4 @@ func testGetServiceById() {
scoreGlobalTestsPassedandFailes(resp.StatusCode, wantedCodes[idx])

}
}
}
3 changes: 1 addition & 2 deletions cmd/patheticTester/testGetServiceByName.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func testGetServiceByName() {
paramMapList := map[string]string{}
serviceNameList := []string{"10", "NonExistantService", goodService.ServiceName}


for idx, testName := range testNameSlice {
fmt.Println("\n~~~~~~~~~~~~~~~~~~~~")
fmt.Printf("Running test %d: - %s\n", idx, testName)
Expand All @@ -32,4 +31,4 @@ func testGetServiceByName() {
scoreGlobalTestsPassedandFailes(resp.StatusCode, wantedCodes[idx])

}
}
}
3 changes: 1 addition & 2 deletions cmd/patheticTester/testGetServiceVersionsById.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func testGetServiceVersionsById() {
paramMapList := map[string]string{}
serviceIdList := []string{"9999999999999", strconv.Itoa(postedServiceData.ServiceId)}


for idx, testName := range testNameSlice {
fmt.Println("\n~~~~~~~~~~~~~~~~~~~~")
fmt.Printf("Running test %d: - %s\n", idx, testName)
Expand All @@ -33,4 +32,4 @@ func testGetServiceVersionsById() {

scoreGlobalTestsPassedandFailes(resp.StatusCode, wantedCodes[idx])
}
}
}
5 changes: 1 addition & 4 deletions cmd/patheticTester/testHealthEndpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import (
func testGetHealthendpoint() {
healthEndpoint := "/health"


testNameSlice := []string{
// Test health 200
"goodCall",
}
wantedCodes := []int{200,}
wantedCodes := []int{200}
paramMapList := map[string]string{}


for idx, testName := range testNameSlice {
fmt.Println("\n~~~~~~~~~~~~~~~~~~~~")
fmt.Printf("Running test %d: - %s\n", idx, testName)
Expand All @@ -32,7 +30,6 @@ func testGetHealthendpoint() {
}

func TestHealthCheck(t *testing.T) {

response, err := http.Get("http://localhost:8969/health")
if err != nil {
t.Errorf("expected no errors, but got %v", err)
Expand Down
79 changes: 38 additions & 41 deletions cmd/patheticTester/testListService.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"github.com/stablecaps/services-api-go/internal/dbtools"
)


func testListServices() {
// list services pathetic tests
endpoint := "/services"


testNameSlice := []string{
// Test 400s
"badLimit", "outOfRangeLimit", "badOffset", "outOfRangeOffset", "badOrderColName", "badOrderDir",
Expand All @@ -24,88 +22,87 @@ func testListServices() {
paramMapList := []map[string]string{
// Test 400s
{
"limit": "fake",
"offset": "0",
"limit": "fake",
"offset": "0",
"orderColName": "serviceName",
"orderDir": "asc",
"orderDir": "asc",
},
{
"limit": "-10",
"offset": "0",
"limit": "-10",
"offset": "0",
"orderColName": "serviceName",
"orderDir": "asc",
"orderDir": "asc",
},
{
"limit": "4",
"offset": "fake",
"limit": "4",
"offset": "fake",
"orderColName": "serviceName",
"orderDir": "asc",
"orderDir": "asc",
},
{
"limit": "4",
"offset": "-10",
"limit": "4",
"offset": "-10",
"orderColName": "serviceName",
"orderDir": "asc",
"orderDir": "asc",
},
{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "fake",
},
{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "serviceName",
"orderDir": "fake",
"orderDir": "fake",
},
// Test orderColName 200
{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "serviceId",
"orderDir": "asc",
"orderDir": "asc",
},
{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "serviceName",
"orderDir": "asc",
"orderDir": "asc",
},
{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "serviceDescription",
"orderDir": "asc",
"orderDir": "asc",
},
{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "serviceVersions",
"orderDir": "asc",
"orderDir": "asc",
},
{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "createdAt",
"orderDir": "asc",
"orderDir": "asc",
},
// Test orderDir 200
{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "serviceName",
"orderDir": "asc",
"orderDir": "asc",
},

{
"limit": "4",
"offset": "0",
"limit": "4",
"offset": "0",
"orderColName": "serviceName",
"orderDir": "asc",
"orderDir": "asc",
},
}


for idx, testName := range testNameSlice {
fmt.Println("\n~~~~~~~~~~~~~~~~~~~~")
fmt.Printf("Running test %d: - %s\n", idx, testName)
Expand Down
4 changes: 0 additions & 4 deletions cmd/populateDb/populateDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
// Declaring Global variables
var baseURL string = "http://localhost:8969/"


func main() {
endpoint := "/services/new"

Expand All @@ -18,14 +17,11 @@ func main() {
numServices := 500
paramMapList := map[string]string{}


for idx := 0; idx <= numServices; idx++ {
log.Printf("Creating service no %d", idx)

body := dbtools.MakeRandomService()
dbtools.MakeHttpRequestWrapper(baseURL, endpoint, "POST", paramMapList, body)

}

}

Loading