Skip to content

Commit 3836b29

Browse files
committed
add small test
1 parent 704a990 commit 3836b29

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ tools/githubjobs/githubjobs: tools/githubjobs/*.go
642642
cd tools/githubjobs && go build .
643643

644644
tools/scandeprecation/scandeprecation: tools/scandeprecation/*.go
645-
cd tools/scandeprecation && go build .
645+
cd tools/scandeprecation && go test . && go build .
646646

647647

648648
.PHONY: slack-deprecations

tools/scandeprecation/scan_deprecations.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,12 @@ func main() {
4747
out.WriteString("|Type|Java Method|Date|\n|------|------|------|\n")
4848

4949
for scanner.Scan() {
50-
example := scanner.Text()
51-
// Non-JSON logs mean we split by tabs
52-
split := strings.Split(example, "\t")
53-
54-
// Last element is the JSON "body" of the log line
55-
example = split[len(split)-1]
56-
example = strings.Replace(example, "***", "{", 1)
57-
example = strings.Replace(example, "***", "}", 1)
58-
59-
res := DeprecationResponse{}
60-
err = json.Unmarshal([]byte(example), &res)
50+
line, err := parseLogLine(scanner.Text())
6151
if err != nil {
62-
log.Warn("failed to unmarshal JSON", zap.Error(err))
52+
log.Warn(err.Error())
6353
continue
6454
}
65-
responses = append(responses, res)
55+
responses = append(responses, line)
6656
}
6757

6858
// Quit out if there is no deprecations logged
@@ -91,3 +81,19 @@ func main() {
9181
// Print to stdout
9282
fmt.Println(out.String())
9383
}
84+
85+
func parseLogLine(line string) (DeprecationResponse, error) {
86+
// Non-JSON logs mean we split by tabs
87+
split := strings.Split(line, "\t")
88+
fmt.Println(split)
89+
90+
// Last element is the JSON "body" of the log line
91+
line = split[len(split)-1]
92+
line = strings.Replace(line, "***", "{", 1)
93+
line = strings.Replace(line, "***", "}", 1)
94+
95+
res := DeprecationResponse{}
96+
err := json.Unmarshal([]byte(line), &res)
97+
98+
return res, err
99+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import "testing"
4+
5+
const testLogLine = `2025-07-21T14:41:06.118Z WARN controllers.AtlasDeployment.deprecated sunset ***"type": "sunset", "date": "Thu, 12 Mar 2026 00:00:00 GMT", "javaMethod": "ApiAtlasSearchDeploymentResource::getSearchDeployment", "path": "/api/atlas/v2/groups/687e4d839dc4c25a9d96f39d/clusters/search-nodes-test/search/deployment", "method": "GET"***`
6+
7+
func TestParseLogLine(t *testing.T) {
8+
out, err := parseLogLine(testLogLine)
9+
if err != nil {
10+
t.Fatal(err)
11+
}
12+
if out.Type != "sunset" && out.Date != "Thu, 12 Mar 2026 00:00:00 GMT" && out.JavaMethod != "ApiAtlasSearchDeploymentResource::getSearchDeployment" {
13+
t.Errorf("parseLogLine did not output expected struct")
14+
}
15+
}
16+
17+
func TestParseLogLineErrors(t *testing.T) {
18+
_, err := parseLogLine("abd123")
19+
if err == nil {
20+
t.Errorf("parseLogLine() did not return an error")
21+
}
22+
}

0 commit comments

Comments
 (0)