From 57499748648c7860eeb2094c4db36f6024ed3536 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 30 Mar 2024 18:37:36 +0000 Subject: [PATCH] chore: Skip tests that require a net connection when offline --- internal/cmd/main_test.go | 6 ++++++ internal/cmd/testdata/scripts/issue2649.txtar | 2 ++ 2 files changed, 8 insertions(+) diff --git a/internal/cmd/main_test.go b/internal/cmd/main_test.go index 4826f49f23f..3f5bef893b9 100644 --- a/internal/cmd/main_test.go +++ b/internal/cmd/main_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io/fs" + "net" "net/http" "net/http/httptest" "os" @@ -31,6 +32,7 @@ import ( var ( envConditionRx = regexp.MustCompile(`\Aenv:(\w+)\z`) envVarRx = regexp.MustCompile(`\$\w+`) + lookupRx = regexp.MustCompile(`\Alookup:(.*)\z`) umaskConditionRx = regexp.MustCompile(`\Aumask:([0-7]{3})\z`) ) @@ -79,6 +81,10 @@ func TestScript(t *testing.T) { if m := envConditionRx.FindStringSubmatch(cond); m != nil { return os.Getenv(m[1]) != "", nil } + if m := lookupRx.FindStringSubmatch(cond); m != nil { + _, err := net.LookupIP(m[1]) + return err == nil, nil + } if m := umaskConditionRx.FindStringSubmatch(cond); m != nil { umask, _ := strconv.ParseInt(m[1], 8, 64) return chezmoitest.Umask == fs.FileMode(umask), nil diff --git a/internal/cmd/testdata/scripts/issue2649.txtar b/internal/cmd/testdata/scripts/issue2649.txtar index 2f7b5b0c675..1c077fa1d97 100644 --- a/internal/cmd/testdata/scripts/issue2649.txtar +++ b/internal/cmd/testdata/scripts/issue2649.txtar @@ -1,3 +1,5 @@ +[!lookup:github.com] skip 'github.com not found' + # test that chezmoi init clones a public dotfiles repo if git is installed [exec:git] exec chezmoi init --use-builtin-git=false chezmoi [exec:git] exists ${CHEZMOISOURCEDIR}/README.md