Skip to content

Commit

Permalink
chore: Skip tests that require a net connection when offline
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Mar 30, 2024
1 parent b366d0e commit 5749974
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/fs"
"net"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -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`)
)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/testdata/scripts/issue2649.txtar
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 5749974

Please sign in to comment.