Skip to content

Commit

Permalink
test: delete networked test
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Dec 5, 2024
1 parent 2cb8179 commit 13a3bcc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 37 deletions.
2 changes: 1 addition & 1 deletion github.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ func findGitHubREADME(u *url.URL) (*source, error) {
}
}

return nil, errors.New(fmt.Sprintf("Can't find README in GitHub repository. Response status: %d %s", res.StatusCode, res.Status))
return nil, errors.New("can't find README in GitHub repository")
}
2 changes: 1 addition & 1 deletion gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ func findGitLabREADME(u *url.URL) (*source, error) {
}
}

return nil, errors.New(fmt.Sprintf("Can't find README in GitLab repository. Response status: %d %s", res.StatusCode, res.Status))
return nil, errors.New("can't find README in GitLab repository")
}
32 changes: 0 additions & 32 deletions glow_test.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
package main

import (
"bytes"
"errors"
"net"
"testing"
)

func TestGlowSources(t *testing.T) {
tt := []string{
".",
"README.md",
"github.com/charmbracelet/glow",
"github://charmbracelet/glow",
"https://github.com/charmbracelet/glow",
}

for _, v := range tt {
t.Run(v, func(t *testing.T) {
buf := &bytes.Buffer{}
err := executeArg(rootCmd, v, buf)
if err != nil {
// Check for network issues.
var netErr *net.DNSError
if errors.As(err, &netErr) {
t.Logf("Error during execution (args: %s): %v", v, err)
t.Skip("Test uses network. Are you connected to the Internet?")
}
t.Errorf("Error during execution (args: %s): %v", v, err)
}
if buf.Len() == 0 {
t.Errorf("Output buffer should not be empty (args: %s)", v)
}
})
}
}

func TestGlowFlags(t *testing.T) {
tt := []struct {
args []string
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func sourceFromArg(arg string) (*source, error) {

// a GitHub or GitLab URL (even without the protocol):
src, err := readmeURL(arg)
if src != nil {
// if there's a valid URL created, exit.
return src, err
if src != nil && err == nil {
// if there's an error, try next methods...
return src, nil
}

// HTTP(S) URLs:
Expand Down

0 comments on commit 13a3bcc

Please sign in to comment.