Skip to content

Commit f0dfda6

Browse files
committed
fixig gh template test
1 parent aa9cc26 commit f0dfda6

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
package customtemplates
22

33
import (
4+
"bytes"
45
"context"
5-
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89

910
"github.com/projectdiscovery/gologger"
1011
"github.com/projectdiscovery/gologger/levels"
1112
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
1213
"github.com/projectdiscovery/nuclei/v3/pkg/testutils"
14+
"github.com/projectdiscovery/nuclei/v3/pkg/utils"
1315
"github.com/stretchr/testify/require"
1416
)
1517

16-
// stdoutWriter adapts os.Stdout to the gologger writer interface
17-
type stdoutWriter struct{}
18-
19-
func (w *stdoutWriter) Write(data []byte, level levels.Level) {
20-
os.Stdout.Write(data)
21-
}
22-
2318
func TestDownloadCustomTemplatesFromGitHub(t *testing.T) {
24-
// if osutils.IsOSX() {
25-
// t.Skip("skipping on macos due to unknown failure (works locally)")
26-
// }
27-
28-
gologger.DefaultLogger.SetWriter(&stdoutWriter{})
19+
// Capture output to check for rate limit errors
20+
outputBuffer := &bytes.Buffer{}
21+
gologger.DefaultLogger.SetWriter(&utils.CaptureWriter{Buffer: outputBuffer})
2922
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
3023

3124
templatesDirectory := t.TempDir()
@@ -39,5 +32,11 @@ func TestDownloadCustomTemplatesFromGitHub(t *testing.T) {
3932

4033
ctm.Download(context.Background())
4134

35+
// Check if output contains rate limit error and skip test if so
36+
output := outputBuffer.String()
37+
if strings.Contains(output, "API rate limit exceeded") {
38+
t.Skip("GitHub API rate limit exceeded, skipping test")
39+
}
40+
4241
require.DirExists(t, filepath.Join(templatesDirectory, "github", "projectdiscovery", "nuclei-templates-test"), "cloned directory does not exists")
4342
}

pkg/utils/capture_writer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package utils
2+
3+
import (
4+
"bytes"
5+
6+
"github.com/projectdiscovery/gologger/levels"
7+
)
8+
9+
// CaptureWriter captures log output for testing
10+
type CaptureWriter struct {
11+
Buffer *bytes.Buffer
12+
}
13+
14+
func (w *CaptureWriter) Write(data []byte, level levels.Level) {
15+
w.Buffer.Write(data)
16+
}

0 commit comments

Comments
 (0)