Skip to content

Commit

Permalink
WIP #348 - Just output stuff and fail
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-r-west committed Jun 17, 2023
1 parent 79b7584 commit 04db595
Showing 1 changed file with 60 additions and 40 deletions.
100 changes: 60 additions & 40 deletions external/resources/yaml/resources_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/yosida95/uritemplate/v3"
"gopkg.in/yaml.v3"
"net/http"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -164,43 +165,62 @@ func TestJsonSchemaValidate(t *testing.T) {
}
}

//func TestResourceDocsExist(t *testing.T) {
// const httpStatusCodeOk = 200
//
// Resources := resources.GetPluralResources()
// linksReferenceCount := make(map[string]int, len(Resources))
//
// for resource := range Resources {
// linksReferenceCount[Resources[resource].Docs]++
// if Resources[resource].GetCollectionInfo != nil {
// linksReferenceCount[Resources[resource].GetCollectionInfo.Docs]++
// }
// if Resources[resource].CreateEntityInfo != nil {
// linksReferenceCount[Resources[resource].CreateEntityInfo.Docs]++
// }
// if Resources[resource].GetEntityInfo != nil {
// linksReferenceCount[Resources[resource].GetEntityInfo.Docs]++
// }
// if Resources[resource].UpdateEntityInfo != nil {
// linksReferenceCount[Resources[resource].UpdateEntityInfo.Docs]++
// }
// if Resources[resource].DeleteEntityInfo != nil {
// linksReferenceCount[Resources[resource].DeleteEntityInfo.Docs]++
// }
// }
//
// for link := range linksReferenceCount {
// response, err := http.DefaultClient.Head(link)
// if err != nil {
// t.Errorf("Error Retrieving Link\nLink: %s\nError Message: %s\nReference Count: %d", link, err, linksReferenceCount[link])
// } else {
// if response.StatusCode != httpStatusCodeOk {
// t.Errorf("Unexpected Response\nLink: %s\nExpected Status Code: %d\nActual Status Code: %d\nReference Count: %d",
// link, httpStatusCodeOk, response.StatusCode, linksReferenceCount[link])
// }
// if err := response.Body.Close(); err != nil {
// t.Errorf("Error Closing Reponse Body\nError Message: %s", err)
// }
// }
// }
//}
func TestResourceDocsExist(t *testing.T) {
const httpStatusCodeOk = 200

Resources := resources.GetPluralResources()
linksReferenceCount := make(map[string]int, len(Resources))

for resource := range Resources {
linksReferenceCount[Resources[resource].Docs]++
if Resources[resource].GetCollectionInfo != nil {
linksReferenceCount[Resources[resource].GetCollectionInfo.Docs]++
}
if Resources[resource].CreateEntityInfo != nil {
linksReferenceCount[Resources[resource].CreateEntityInfo.Docs]++
}
if Resources[resource].GetEntityInfo != nil {
linksReferenceCount[Resources[resource].GetEntityInfo.Docs]++
}
if Resources[resource].UpdateEntityInfo != nil {
linksReferenceCount[Resources[resource].UpdateEntityInfo.Docs]++
}
if Resources[resource].DeleteEntityInfo != nil {
linksReferenceCount[Resources[resource].DeleteEntityInfo.Docs]++
}
}

client := http.Client{
Transport: nil,
CheckRedirect: func(req *http.Request, via []*http.Request) error {

if fmt.Sprint(req.URL) != "https://elasticpath.dev/docs" {
return nil
}

fmt.Printf("%s => %s\n", via[0].URL, req.URL)

return nil
},
Jar: nil,
Timeout: 0,
}
for link := range linksReferenceCount {

response, err := client.Head(link)

if err != nil {
t.Errorf("Error Retrieving Link\nLink: %s\nError Message: %s\nReference Count: %d", link, err, linksReferenceCount[link])
} else {
if response.StatusCode != httpStatusCodeOk {

fmt.Printf("%s => %d\n", link, response.StatusCode)
//t.Errorf("Unexpected Response\nLink: %s\nExpected Status Code: %d\nActual Status Code: %d\nReference Count: %d",
// link, httpStatusCodeOk, response.StatusCode, linksReferenceCount[link])
}
if err := response.Body.Close(); err != nil {
//t.Errorf("Error Closing Reponse Body\nError Message: %s", err)
}
}
}
}

0 comments on commit 04db595

Please sign in to comment.