diff --git a/external/resources/yaml/resources_yaml_test.go b/external/resources/yaml/resources_yaml_test.go index e052af1..e6ed70d 100644 --- a/external/resources/yaml/resources_yaml_test.go +++ b/external/resources/yaml/resources_yaml_test.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/yosida95/uritemplate/v3" "gopkg.in/yaml.v3" + "net/http" "os" "regexp" "strings" @@ -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") +}