Skip to content

Commit

Permalink
Checkpoint #157 - Trying to create one main file, maybe fake data wil…
Browse files Browse the repository at this point in the history
…l make it easier to write tests
  • Loading branch information
steve-r-west committed Jul 25, 2022
1 parent f8d21a0 commit 09014ea
Show file tree
Hide file tree
Showing 67 changed files with 344 additions and 12 deletions.
50 changes: 46 additions & 4 deletions cmd/make-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ import (
)

const testTemplate = `#!/usr/bin/env bats
{{if .GetCollectionInfo -}}
@test "{{ .PluralName }} empty get collection" {
run epcc get {{ .PluralName }}
{{if .resource.GetCollectionInfo -}}
@test "{{ .resource.PluralName }} empty get collection" {
run epcc get {{ .resource.PluralName }}
[ $status -eq 0 ]
}
{{end}}
{{if and .resource.GetCollectionInfo .resource.DeleteEntityInfo -}}
@test "{{ .resource.PluralName }} delete-all support" {
run epcc delete-all {{ .resource.PluralName }}
[ $status -eq 0 ]
}
{{end}}
`

var MakeTests = &cobra.Command{
Expand All @@ -24,11 +31,42 @@ var MakeTests = &cobra.Command{
Hidden: true,

RunE: func(cmd *cobra.Command, args []string) error {

err := os.MkdirAll("tests/resources", 0755)
if err != nil {
return err
}

createResourceString := map[string]string{}

for resourceName, resource := range resources.GetPluralResources() {

createString := fmt.Sprintf("epcc create %s ", resource.PluralName)

if resource.CreateEntityInfo != nil {
for attrName, attrVal := range resource.Attributes {

createString += attrName + " "

switch attrVal.Type {
case "FILE":
case "BOOLEAN":
createString += "true"
case "INT":
createString += "%(date +%s)"
case "STRING":
createString += "string"
default:
createString += "unsupported"
}

}

createResourceString[resourceName] = createString
}

}

for _, resourceName := range resources.GetPluralResourceNames() {
testFilename := fmt.Sprintf("./tests/resources/%s.bats", resourceName)
_, err := os.Stat(testFilename)
Expand All @@ -37,6 +75,7 @@ var MakeTests = &cobra.Command{
log.Infof("Tests for %s do not exist", testFilename)
} else {
log.Infof("Tests for %s exist already", testFilename)

}

tmpl, err := template.New("test").Parse(testTemplate)
Expand All @@ -58,7 +97,10 @@ var MakeTests = &cobra.Command{
return err
}

err = tmpl.Execute(f, resource)
err = tmpl.Execute(f, map[string]interface{}{
"resource": resource,
"create_map": createResourceString,
})

if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion external/httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ func doRequestInternal(ctx context.Context, method string, contentType string, p
log.Debugf("%s %s", method, reqURL.String())

// TODO maybe check if it's json and if not do something else.
json.PrintJson(string(body))
// Log to standard error because the body should always be jqable
json.PrintJsonToStderr(string(body))
log.Debugf("%s %s", resp.Proto, resp.Status)
} else {
log.Debugf("%s %s ==> %s %s", method, reqURL.String(), resp.Proto, resp.Status)
Expand Down
60 changes: 60 additions & 0 deletions tests/resource_smoke_test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bats

#setup_file() {
# #run epcc reset-store .+
# #[ $status -eq 0 ]
#}
setup() {
load 'test_helper/bats-support/load' # this is required by bats-assert!
load 'test_helper/bats-assert/load'

}

@test "account-addresses crud smoke test" {

# Fixture Setup
run epcc delete-all accounts
[ $status -eq 0 ]
run epcc delete-all account-addresses
[ $status -eq 0 ]
run epcc create account name account-addresses-test legal_name my_legal_name
[ $status -eq 0 ]

# Execute SUT
[ $status -eq 0 ]
run epcc get account-addresses name=account-addresses-test
[ $status -eq 0 ]
run epcc create account-addresses name=account-addresses-test name test legal_name my_legal_name
[ $status -eq 0 ]
run epcc update account-addresses name=account-addresses-test name=test name test2
[ $status -eq 0 ]
run epcc get account-addresses name=account-addresses-test
[ $status -eq 0 ]
assert_output --partial '"name": "test2",'
run epcc get account-addresses name=test2
assert_output --partial '"legal_name": "my_legal_name",'

# Verification



}


@test "accounts crud smoke test" {
run epcc delete-all accounts
[ $status -eq 0 ]
run epcc get accounts
[ $status -eq 0 ]
run epcc create account name test legal_name my_legal_name
[ $status -eq 0 ]
run epcc update account name=test name test2
[ $status -eq 0 ]
run epcc get accounts
[ $status -eq 0 ]
assert_output --partial '"name": "test2",'
run epcc get account name=test2
assert_output --partial '"legal_name": "my_legal_name",'
}


6 changes: 6 additions & 0 deletions tests/resources/account-addresses.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "account-addresses delete-all support" {
run epcc delete-all account-addresses
[ $status -eq 0 ]
}


1 change: 0 additions & 1 deletion tests/resources/account-authentication-settings.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
run epcc get account-authentication-settings
[ $status -eq 0 ]
}

2 changes: 2 additions & 0 deletions tests/resources/account-management-authentication-tokens.bats
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bats



2 changes: 2 additions & 0 deletions tests/resources/account-members.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



6 changes: 6 additions & 0 deletions tests/resources/account-memberships.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "account-memberships delete-all support" {
run epcc delete-all account-memberships
[ $status -eq 0 ]
}


6 changes: 0 additions & 6 deletions tests/resources/accounts.bats
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
#!/usr/bin/env bats
@test "accounts empty get collection" {
run epcc get accounts
[ $status -eq 0 ]
}

2 changes: 2 additions & 0 deletions tests/resources/authentication-realms.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



2 changes: 2 additions & 0 deletions tests/resources/cart-checkout.bats
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bats



6 changes: 6 additions & 0 deletions tests/resources/cart-items.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "cart-items delete-all support" {
run epcc delete-all cart-items
[ $status -eq 0 ]
}


2 changes: 2 additions & 0 deletions tests/resources/cart-product-items.bats
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bats



6 changes: 6 additions & 0 deletions tests/resources/carts.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "carts delete-all support" {
run epcc delete-all carts
[ $status -eq 0 ]
}


2 changes: 2 additions & 0 deletions tests/resources/catalog-products.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



6 changes: 6 additions & 0 deletions tests/resources/currencies.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "currencies delete-all support" {
run epcc delete-all currencies
[ $status -eq 0 ]
}


6 changes: 6 additions & 0 deletions tests/resources/customer-addresses.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "customer-addresses delete-all support" {
run epcc delete-all customer-addresses
[ $status -eq 0 ]
}


2 changes: 2 additions & 0 deletions tests/resources/customer-authentication-settings.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



6 changes: 6 additions & 0 deletions tests/resources/customers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "customers delete-all support" {
run epcc delete-all customers
[ $status -eq 0 ]
}


6 changes: 6 additions & 0 deletions tests/resources/fields.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "fields delete-all support" {
run epcc delete-all fields
[ $status -eq 0 ]
}


6 changes: 6 additions & 0 deletions tests/resources/files.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "files delete-all support" {
run epcc delete-all files
[ $status -eq 0 ]
}


6 changes: 6 additions & 0 deletions tests/resources/flows.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "flows delete-all support" {
run epcc delete-all flows
[ $status -eq 0 ]
}


2 changes: 2 additions & 0 deletions tests/resources/integration-job-log.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



2 changes: 2 additions & 0 deletions tests/resources/integration-jobs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



2 changes: 2 additions & 0 deletions tests/resources/integration-logs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



6 changes: 6 additions & 0 deletions tests/resources/integrations.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "integrations delete-all support" {
run epcc delete-all integrations
[ $status -eq 0 ]
}


2 changes: 2 additions & 0 deletions tests/resources/merchant-realm-mappings.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



6 changes: 6 additions & 0 deletions tests/resources/oidc-profiles.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "oidc-profiles delete-all support" {
run epcc delete-all oidc-profiles
[ $status -eq 0 ]
}


2 changes: 2 additions & 0 deletions tests/resources/order-items.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



2 changes: 2 additions & 0 deletions tests/resources/order-transaction-capture.bats
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bats



2 changes: 2 additions & 0 deletions tests/resources/order-transaction-refund.bats
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bats



2 changes: 2 additions & 0 deletions tests/resources/order-transactions.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



2 changes: 2 additions & 0 deletions tests/resources/orders.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[ $status -eq 0 ]
}



6 changes: 6 additions & 0 deletions tests/resources/password-profiles.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[ $status -eq 0 ]
}

@test "password-profiles delete-all support" {
run epcc delete-all password-profiles
[ $status -eq 0 ]
}


2 changes: 2 additions & 0 deletions tests/resources/payment-gateways-adyen.bats
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bats



2 changes: 2 additions & 0 deletions tests/resources/payment-gateways-authorize-net.bats
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bats



Loading

0 comments on commit 09014ea

Please sign in to comment.