Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 348 #349

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
102 changes: 62 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,64 @@ 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)
}
}
}

t.Errorf("Incomplete")
}