Skip to content

Commit 565df46

Browse files
committed
Rename ID to Id
1 parent 78c6dbe commit 565df46

9 files changed

Lines changed: 48 additions & 51 deletions

File tree

internal/api/submit/request.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type System struct {
66

77
type OS struct {
88
Architecture string `json:"architecture"`
9-
ID string `json:"id"`
9+
Id string `json:"id"`
1010
}
1111

1212
type Pacman struct {
@@ -31,7 +31,7 @@ type PackageManager interface {
3131
type SystemInfo interface {
3232
GetCpuArchitecture() (string, error)
3333
GetArchitecture() (string, error)
34-
GetOSID() (string, error)
34+
GetOSId() (string, error)
3535
}
3636

3737
func CreateRequest(p PackageManager, s SystemInfo) (*Request, error) {
@@ -53,15 +53,15 @@ func CreateRequest(p PackageManager, s SystemInfo) (*Request, error) {
5353
return nil, err
5454
}
5555

56-
osId, err := s.GetOSID()
56+
osId, err := s.GetOSId()
5757
if err != nil {
5858
return nil, err
5959
}
6060

6161
return &Request{
6262
Version: Version,
6363
System: System{Architecture: cpuArchitecture},
64-
OS: OS{Architecture: architecture, ID: osId},
64+
OS: OS{Architecture: architecture, Id: osId},
6565
Pacman: Pacman{Packages: packages, Mirror: mirror},
6666
}, nil
6767
}

internal/system/system_goos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ func (s *System) GetArchitecture() (string, error) {
1717
}
1818
}
1919

20-
func (s *System) GetOSID() (string, error) {
20+
func (s *System) GetOSId() (string, error) {
2121
return runtime.GOOS, nil
2222
}

internal/system/system_linux.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ func (s *System) GetArchitecture() (string, error) {
1919
return string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]), nil
2020
}
2121

22-
func (s *System) GetOSID() (string, error) {
22+
func (s *System) GetOSId() (string, error) {
2323
for _, path := range []string{"/etc/os-release", "/usr/lib/os-release"} {
2424
content, err := os.ReadFile(path)
2525
if err != nil {
2626
continue
2727
}
28-
if id := ParseOSID(content); id != "" {
28+
if id := ParseOSId(content); id != "" {
2929
return id, nil
3030
}
3131
break
@@ -34,8 +34,7 @@ func (s *System) GetOSID() (string, error) {
3434
return runtime.GOOS, nil
3535
}
3636

37-
// ParseOSID parses the ID field from os-release file content.
38-
func ParseOSID(content []byte) string {
37+
func ParseOSId(content []byte) string {
3938
var id string
4039

4140
lines := strings.Split(string(content), "\n")

tests/integration/integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestShowInformationToBeSent(t *testing.T) {
4343
if err != nil {
4444
t.Fatal(err)
4545
}
46-
osId, err := s.GetOSID()
46+
osId, err := s.GetOSId()
4747
if err != nil {
4848
t.Fatal(err)
4949
}
@@ -65,8 +65,8 @@ func TestShowInformationToBeSent(t *testing.T) {
6565
if request.OS.Architecture != osArchitecture {
6666
t.Errorf("Expected OS architecture '%s', got %v", osArchitecture, request.OS.Architecture)
6767
}
68-
if request.OS.ID != osId {
69-
t.Errorf("Expected OS id '%s', got %v", osId, request.OS.ID)
68+
if request.OS.Id != osId {
69+
t.Errorf("Expected OS id '%s', got %v", osId, request.OS.Id)
7070
}
7171
if !strings.HasPrefix(request.Pacman.Mirror, "https://") {
7272
t.Errorf("Expected pacman mirror to start with 'https://', got %v", request.Pacman.Mirror)

tests/integration/mock_server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func validateSubmitRequest(w http.ResponseWriter, request *submit.Request) {
108108
http.Error(w, err.Error(), http.StatusInternalServerError)
109109
return
110110
}
111-
osId, err := s.GetOSID()
111+
osId, err := s.GetOSId()
112112
if err != nil {
113113
http.Error(w, err.Error(), http.StatusInternalServerError)
114114
return
@@ -122,8 +122,8 @@ func validateSubmitRequest(w http.ResponseWriter, request *submit.Request) {
122122
http.Error(w, fmt.Sprintf("Expected OS architecture %s, got %s", osArchitecture, request.OS.Architecture), http.StatusBadRequest)
123123
return
124124
}
125-
if request.OS.ID != osId {
126-
http.Error(w, fmt.Sprintf("Expected OS id %s, got %s", osId, request.OS.ID), http.StatusBadRequest)
125+
if request.OS.Id != osId {
126+
http.Error(w, fmt.Sprintf("Expected OS id %s, got %s", osId, request.OS.Id), http.StatusBadRequest)
127127
return
128128
}
129129
if request.System.Architecture != cpuArchitecture {

tests/unit/internal/api/submit/client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestSendRequest(t *testing.T) {
3333
request := &submit.Request{
3434
Version: submit.Version,
3535
System: submit.System{Architecture: system.X86_64},
36-
OS: submit.OS{Architecture: system.I686, ID: runtime.GOOS},
36+
OS: submit.OS{Architecture: system.I686, Id: runtime.GOOS},
3737
Pacman: submit.Pacman{Packages: []string{"pacman", "linux"}, Mirror: mirror},
3838
}
3939
err := client.SendRequest(*request)
@@ -75,7 +75,7 @@ func validateRequest(t *testing.T, req *http.Request) {
7575
if request.OS.Architecture != system.I686 {
7676
t.Error("Invalid arch value")
7777
}
78-
if request.OS.ID != runtime.GOOS {
78+
if request.OS.Id != runtime.GOOS {
7979
t.Error("Invalid id value")
8080
}
8181
if request.Pacman.Mirror != mirror {
@@ -105,7 +105,7 @@ func TestSendRequestFollowsRedirect(t *testing.T) {
105105
request := &submit.Request{
106106
Version: submit.Version,
107107
System: submit.System{Architecture: system.X86_64},
108-
OS: submit.OS{Architecture: system.I686, ID: runtime.GOOS},
108+
OS: submit.OS{Architecture: system.I686, Id: runtime.GOOS},
109109
Pacman: submit.Pacman{Packages: []string{"pacman", "linux"}, Mirror: mirror},
110110
}
111111
err := client.SendRequest(*request)
@@ -132,7 +132,7 @@ func TestReturnServerErrorOnFailure(t *testing.T) {
132132
request := &submit.Request{
133133
Version: submit.Version,
134134
System: submit.System{Architecture: system.X86_64},
135-
OS: submit.OS{Architecture: system.I686, ID: runtime.GOOS},
135+
OS: submit.OS{Architecture: system.I686, Id: runtime.GOOS},
136136
Pacman: submit.Pacman{Packages: []string{"pacman", "linux"}, Mirror: mirror},
137137
}
138138
err := client.SendRequest(*request)

tests/unit/internal/system/parse_test.go renamed to tests/unit/internal/system/parse_linux_test.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build linux
2-
31
package system_test
42

53
import (
@@ -8,75 +6,75 @@ import (
86
"pkgstats-cli/internal/system"
97
)
108

11-
func TestParseOSID(t *testing.T) {
9+
func TestParseOSId(t *testing.T) {
1210
testCases := []struct {
1311
name string
1412
content string
15-
expectedOSID string
13+
expectedOSId string
1614
}{
1715
{
18-
name: "should return ID from simple content",
16+
name: "should return Id from simple content",
1917
content: `
2018
NAME="Test OS"
2119
VERSION="1.0"
2220
ID=testos
2321
ID_LIKE=anotheros
2422
`,
25-
expectedOSID: "testos",
23+
expectedOSId: "testos",
2624
},
2725
{
28-
name: "should return ID from double-quoted syntax with whitespaces",
26+
name: "should return Id from double-quoted syntax with whitespaces",
2927
content: `
3028
NAME="Test OS"
3129
VERSION="1.0"
3230
ID = "testos"
3331
ID_LIKE=anotheros
3432
`,
35-
expectedOSID: "testos",
33+
expectedOSId: "testos",
3634
},
3735
{
38-
name: "should return ID with whitespaces",
36+
name: "should return Id with whitespaces",
3937
content: `
4038
NAME="Test OS"
4139
VERSION="1.0"
4240
ID = testos
4341
ID_LIKE=anotheros
4442
`,
45-
expectedOSID: "testos",
43+
expectedOSId: "testos",
4644
},
4745
{
48-
name: "should return ID from single-quoted syntax",
46+
name: "should return Id from single-quoted syntax",
4947
content: `
5048
NAME="Test OS"
5149
VERSION="1.0"
5250
ID='testos'
5351
ID_LIKE=anotheros
5452
`,
55-
expectedOSID: "testos",
53+
expectedOSId: "testos",
5654
},
5755
{
58-
name: "should return the last ID when duplicates exist",
56+
name: "should return the last Id when duplicates exist",
5957
content: `
6058
ID=firstid
6159
NAME="Test OS"
6260
ID=secondid
6361
VERSION="1.0"
6462
ID=lastid
6563
`,
66-
expectedOSID: "lastid",
64+
expectedOSId: "lastid",
6765
},
6866
{
6967
name: "should return empty string for empty content",
7068
content: "",
71-
expectedOSID: "",
69+
expectedOSId: "",
7270
},
7371
{
74-
name: "should return empty string for content with no ID",
72+
name: "should return empty string for content with no Id",
7573
content: `
7674
NAME="Test OS"
7775
VERSION="1.0"
7876
`,
79-
expectedOSID: "",
77+
expectedOSId: "",
8078
},
8179
{
8280
name: "should ignore comments",
@@ -85,22 +83,22 @@ VERSION="1.0"
8583
NAME="Test OS"
8684
ID=actual
8785
`,
88-
expectedOSID: "actual",
86+
expectedOSId: "actual",
8987
},
9088
{
91-
name: "should handle ID with embedded equals",
89+
name: "should handle Id with embedded equals",
9290
content: `
9391
ID=some=value
9492
`,
95-
expectedOSID: "some=value",
93+
expectedOSId: "some=value",
9694
},
9795
}
9896

9997
for _, tc := range testCases {
10098
t.Run(tc.name, func(t *testing.T) {
101-
osID := system.ParseOSID([]byte(tc.content))
102-
if osID != tc.expectedOSID {
103-
t.Errorf("expected OSID %q, got %q", tc.expectedOSID, osID)
99+
osId := system.ParseOSId([]byte(tc.content))
100+
if osId != tc.expectedOSId {
101+
t.Errorf("expected OSId %q, got %q", tc.expectedOSId, osId)
104102
}
105103
})
106104
}

tests/unit/internal/system/system_goos_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func TestGetArchitecture(t *testing.T) {
1919
}
2020
}
2121

22-
func TestGetOSID(t *testing.T) {
23-
osId, err := system.NewSystem().GetOSID()
22+
func TestGetOSId(t *testing.T) {
23+
osId, err := system.NewSystem().GetOSId()
2424
if err != nil {
2525
t.Error(err)
2626
}

tests/unit/internal/system/system_linux_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ func TestGetMachine(t *testing.T) {
3535
}
3636
}
3737

38-
func TestGetOSID(t *testing.T) {
38+
func TestGetOSId(t *testing.T) {
3939
sys := system.NewSystem()
40-
osID, err := sys.GetOSID()
40+
osId, err := sys.GetOSId()
4141
if err != nil {
42-
t.Fatalf("unexpected error getting OSID: %v", err)
42+
t.Fatalf("unexpected error getting OSId: %v", err)
4343
}
4444

4545
_, err1 := os.Stat("/etc/os-release")
4646
_, err2 := os.Stat("/usr/lib/os-release")
4747

4848
if os.IsNotExist(err1) && os.IsNotExist(err2) {
49-
if osID != runtime.GOOS {
50-
t.Errorf("expected OSID %q, got %q", runtime.GOOS, osID)
49+
if osId != runtime.GOOS {
50+
t.Errorf("expected OSId %q, got %q", runtime.GOOS, osId)
5151
}
5252
} else {
53-
if osID == "" {
54-
t.Error("expected a non-empty OSID, but it was empty")
53+
if osId == "" {
54+
t.Error("expected a non-empty OSId, but it was empty")
5555
}
5656
}
5757
}

0 commit comments

Comments
 (0)