Skip to content

Commit 1ce50fb

Browse files
test: add tests for Yellow and Cyan color functions
1 parent c16ebf8 commit 1ce50fb

7 files changed

Lines changed: 49 additions & 13 deletions

File tree

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414

1515
steps:
1616
- name: Set up Go 1.x
17-
uses: actions/setup-go@v6
17+
uses: actions/setup-go@v5
1818
with:
1919
go-version: '1.25.5'
2020

2121
- name: Check out code into the Go module directory
22-
uses: actions/checkout@v6
22+
uses: actions/checkout@v4
2323
with:
2424
fetch-depth: 1
2525
ref: ${{ github.event.pull_request.head.sha }}

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v6
16+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
1717
with:
1818
fetch-depth: 0
1919
submodules: 'true'
2020

2121
- name: Set up Go
22-
uses: actions/setup-go@v6
22+
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
2323
with:
2424
go-version: '1.25.5'
2525

command/config/validate/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (o *Options) Run() error {
6161
// Read the config in the form of string and send it
6262
content, err := os.ReadFile(configPath)
6363
if err != nil {
64-
return fmt.Errorf("error occured while reading DeepSource config file %s: %w", configPath, err)
64+
return fmt.Errorf("error occurred while reading DeepSource config file %s: %w", configPath, err)
6565
}
6666

6767
// Fetch the client

command/issues/list/list_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ func TestListSARIF(t *testing.T) {
8888
opts.exportSARIF("./testdata/exported.sarif")
8989

9090
// read exported and test SARIF files
91-
exported, _ := os.ReadFile("./testdata/exported.sarif")
92-
test, _ := os.ReadFile("./testdata/sarif/test.sarif")
91+
exported, err := os.ReadFile("./testdata/exported.sarif")
92+
if err != nil {
93+
t.Fatal(err)
94+
}
95+
test, err := os.ReadFile("./testdata/sarif/test.sarif")
96+
if err != nil {
97+
t.Fatal(err)
98+
}
9399

94100
// trim carriage returns
95101
got := strings.TrimSuffix(string(exported), "\n")
@@ -111,8 +117,14 @@ func TestListSARIF(t *testing.T) {
111117
opts.exportSARIF("./testdata/exported_multi.sarif")
112118

113119
// read exported and test SARIF files
114-
exported, _ := os.ReadFile("./testdata/exported_multi.sarif")
115-
test, _ := os.ReadFile("./testdata/sarif/test_multi.sarif")
120+
exported, err := os.ReadFile("./testdata/exported_multi.sarif")
121+
if err != nil {
122+
t.Fatal(err)
123+
}
124+
test, err := os.ReadFile("./testdata/sarif/test_multi.sarif")
125+
if err != nil {
126+
t.Fatal(err)
127+
}
116128

117129
// trim carriage returns
118130
got := strings.TrimSuffix(string(exported), "\n")

deepsource/tests/get_analyzers_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func mockAnalyzer(w http.ResponseWriter, r *http.Request) {
7474
errorResponseBodyData, err := os.ReadFile("./testdata/analyzer/error_response_body.json")
7575
if err != nil {
7676
log.Println(err)
77+
http.Error(w, "Failed to read test data", http.StatusInternalServerError)
7778
return
7879
}
7980

deepsource/tests/init_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ func TestMain(m *testing.M) {
2121
srv.Close()
2222
os.Exit(code)
2323
}
24-
24+
const (
25+
mockServerAddress = "localhost:8081"
26+
serverReadyMaxRetries = 200
27+
serverReadyRetryInterval = 10 * time.Millisecond
28+
)
2529
func startMockAPIServer() {
2630
// Start GraphQL server for test
2731
srv = &http.Server{
@@ -38,13 +42,13 @@ func startMockAPIServer() {
3842
}()
3943

4044
// Wait for server to be ready
41-
for i := 0; i < 200; i++ {
42-
conn, err := net.Dial("tcp", "localhost:8081")
45+
for i := 0; i < serverReadyMaxRetries; i++ {
46+
conn, err := net.Dial("tcp", mockServerAddress)
4347
if err == nil {
4448
conn.Close()
4549
return
4650
}
47-
time.Sleep(10 * time.Millisecond)
51+
time.Sleep(serverReadyRetryInterval)
4852
}
4953
panic("mock server failed to start within timeout")
5054
}

utils/colors_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package utils
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestYellow(t *testing.T) {
10+
result := Yellow("test")
11+
assert.NotEmpty(t, result)
12+
assert.Contains(t, result, "test")
13+
}
14+
15+
func TestCyan(t *testing.T) {
16+
result := Cyan("test")
17+
assert.NotEmpty(t, result)
18+
assert.Contains(t, result, "test")
19+
}

0 commit comments

Comments
 (0)