diff options
author | Franck Cuny <franck@fcuny.net> | 2022-06-14 17:39:25 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2022-06-15 17:46:15 -0700 |
commit | f5b2016cbbbdf1dc999845095c267b1cffb62352 (patch) | |
tree | 81b0c692f7faac8dd268cefc2a28a7980272e9ff /tools/govanity | |
parent | fix(tools/govanity): remove one repo and fix URL for the other two (diff) | |
download | world-f5b2016cbbbdf1dc999845095c267b1cffb62352.tar.gz |
fix(tools/govanity): add a test for the repo URL
This test does an HTTP request to ensure the URL for the repository does not return an error. The test tries first to do a DNS resolution to see if we have network access. When we build the binary in the nix sandbox we don't have network access, so we don't want to fail in this situation, we only want to skip. The test is going to be run before we do a deployment. Change-Id: I184f9208210432a5394158d728e556c949e63a24 Reviewed-on: https://cl.fcuny.net/c/world/+/419 Tested-by: CI Reviewed-by: Franck Cuny <franck@fcuny.net>
Diffstat (limited to 'tools/govanity')
-rw-r--r-- | tools/govanity/e2e_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/govanity/e2e_test.go b/tools/govanity/e2e_test.go new file mode 100644 index 0000000..4ec299a --- /dev/null +++ b/tools/govanity/e2e_test.go @@ -0,0 +1,40 @@ +package main + +import ( + "io/ioutil" + "net" + "net/http" + "testing" + + "gopkg.in/yaml.v3" +) + +func TestConfigurationURL(t *testing.T) { + // we try a DNS resolution first. If it fails, it means we're + // likely in the sandbox, and we need to skip this test. + _, err := net.LookupHost("fcuny.net") + if err != nil { + t.Skipf("no network connectivity: %v", err) + } + + buf, err := ioutil.ReadFile("vanity.yaml") + if err != nil { + t.Fatalf("failed to read the configuration file: %v", err) + } + + cfg := &config{} + err = yaml.Unmarshal(buf, cfg) + if err != nil { + t.Fatalf("failed to parse the YAML configuration: %v", err) + } + + for _, r := range cfg.Repositories { + res, err := http.Get(r.Repo) + if err != nil { + t.Errorf("failed to request %s: %v", r.Repo, err) + } + if res.StatusCode != http.StatusOK { + t.Errorf("HTTP status for %s is: %d - %s", r.Repo, res.StatusCode, res.Status) + } + } +} |