From f5b2016cbbbdf1dc999845095c267b1cffb62352 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Tue, 14 Jun 2022 17:39:25 -0700 Subject: 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 --- tools/govanity/e2e_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tools/govanity/e2e_test.go 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) + } + } +} -- cgit 1.4.1