Skip to content

Commit 9825d66

Browse files
authored
Some API cleanup (#2340)
1 parent 04da9ad commit 9825d66

File tree

12 files changed

+51
-79
lines changed

12 files changed

+51
-79
lines changed

api/client/client_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func TestGetInstallationConfig(t *testing.T) {
121121
c := New(server.URL, WithToken("test-token"))
122122
config, err := c.GetInstallationConfig()
123123
assert.NoError(t, err)
124-
assert.NotNil(t, config)
125124
assert.Equal(t, "10.0.0.0/24", config.GlobalCIDR)
126125
assert.Equal(t, 8080, config.AdminConsolePort)
127126

@@ -179,7 +178,6 @@ func TestConfigureInstallation(t *testing.T) {
179178
}
180179
status, err := c.ConfigureInstallation(config)
181180
assert.NoError(t, err)
182-
assert.NotNil(t, status)
183181
assert.Equal(t, types.StateRunning, status.State)
184182
assert.Equal(t, "Configuring installation", status.Description)
185183

@@ -228,8 +226,6 @@ func TestSetupInfra(t *testing.T) {
228226
c := New(server.URL, WithToken("test-token"))
229227
infra, err := c.SetupInfra()
230228
assert.NoError(t, err)
231-
assert.NotNil(t, infra)
232-
assert.NotNil(t, infra.Status)
233229
assert.Equal(t, types.StateRunning, infra.Status.State)
234230
assert.Equal(t, "Installing infra", infra.Status.Description)
235231

@@ -278,7 +274,6 @@ func TestGetInfraStatus(t *testing.T) {
278274
c := New(server.URL, WithToken("test-token"))
279275
infra, err := c.GetInfraStatus()
280276
assert.NoError(t, err)
281-
assert.NotNil(t, infra)
282277
assert.Equal(t, types.StateSucceeded, infra.Status.State)
283278
assert.Equal(t, "Installation successful", infra.Status.Description)
284279

@@ -331,7 +326,6 @@ func TestSetInstallStatus(t *testing.T) {
331326
}
332327
newStatus, err := c.SetInstallStatus(status)
333328
assert.NoError(t, err)
334-
assert.NotNil(t, newStatus)
335329
assert.Equal(t, status, newStatus)
336330

337331
// Test error response

api/integration/auth_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ func TestAPIClientLogin(t *testing.T) {
162162
require.NoError(t, err, "API client login should succeed with correct password")
163163

164164
// Verify we can make authenticated requests after login
165-
status, err := c.GetInstallationStatus()
165+
_, err = c.GetInstallationStatus()
166166
require.NoError(t, err, "API client should be able to get installation status after successful login")
167-
assert.NotNil(t, status, "Installation status should not be nil")
168167
})
169168

170169
// Test failed login with incorrect password

api/integration/install_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,6 @@ func TestInstallWithAPIClient(t *testing.T) {
10121012
t.Run("GetInstallationConfig", func(t *testing.T) {
10131013
config, err := c.GetInstallationConfig()
10141014
require.NoError(t, err, "GetInstallationConfig should succeed")
1015-
assert.NotNil(t, config, "InstallationConfig should not be nil")
10161015

10171016
// Verify values
10181017
assert.Equal(t, "/tmp/test-data-for-client", config.DataDirectory)
@@ -1026,7 +1025,6 @@ func TestInstallWithAPIClient(t *testing.T) {
10261025
t.Run("GetInstallationStatus", func(t *testing.T) {
10271026
status, err := c.GetInstallationStatus()
10281027
require.NoError(t, err, "GetInstallationStatus should succeed")
1029-
assert.NotNil(t, status, "InstallationStatus should not be nil")
10301028
assert.Equal(t, types.StatePending, status.State)
10311029
assert.Equal(t, "Installation pending", status.Description)
10321030
})
@@ -1043,9 +1041,8 @@ func TestInstallWithAPIClient(t *testing.T) {
10431041
}
10441042

10451043
// Configure the installation using the client
1046-
status, err := c.ConfigureInstallation(config)
1044+
_, err = c.ConfigureInstallation(config)
10471045
require.NoError(t, err, "ConfigureInstallation should succeed with valid config")
1048-
assert.NotNil(t, status, "Status should not be nil")
10491046

10501047
// Verify the status was set correctly
10511048
var installStatus types.Status
@@ -1107,7 +1104,6 @@ func TestInstallWithAPIClient(t *testing.T) {
11071104
// Set the status using the client
11081105
newStatus, err := c.SetInstallStatus(status)
11091106
require.NoError(t, err, "SetInstallStatus should succeed")
1110-
assert.NotNil(t, newStatus, "Install should not be nil")
11111107
assert.Equal(t, status, newStatus, "Install status should match the one set")
11121108
})
11131109
}
@@ -1300,7 +1296,6 @@ func TestPostSetupInfra(t *testing.T) {
13001296
// Verify installation was created
13011297
gotInst, err := kubeutils.GetLatestInstallation(t.Context(), fakeKcli)
13021298
require.NoError(t, err)
1303-
assert.NotNil(t, gotInst)
13041299
assert.Equal(t, ecv1beta1.InstallationStateInstalled, gotInst.Status.State)
13051300

13061301
// Verify version metadata configmap was created

api/internal/managers/installation/config_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,6 @@ func TestSetConfigDefaults(t *testing.T) {
286286

287287
err := manager.SetConfigDefaults(&tt.inputConfig)
288288
assert.NoError(t, err)
289-
290-
assert.NotNil(t, tt.inputConfig)
291289
assert.Equal(t, tt.expectedConfig, tt.inputConfig)
292290
})
293291
}
@@ -326,7 +324,6 @@ func TestConfigSetAndGet(t *testing.T) {
326324
// Test reading it back
327325
readConfig, err := manager.GetConfig()
328326
assert.NoError(t, err)
329-
assert.NotNil(t, readConfig)
330327

331328
// Verify the values match
332329
assert.Equal(t, configToWrite.AdminConsolePort, readConfig.AdminConsolePort)

api/internal/managers/installation/status_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func TestStatusSetAndGet(t *testing.T) {
2525
// Test reading it back
2626
readStatus, err := manager.GetStatus()
2727
assert.NoError(t, err)
28-
assert.NotNil(t, readStatus)
2928

3029
// Verify the values match
3130
assert.Equal(t, statusToWrite.State, readStatus.State)
@@ -46,7 +45,6 @@ func TestSetRunningStatus(t *testing.T) {
4645

4746
status, err := manager.GetStatus()
4847
assert.NoError(t, err)
49-
assert.NotNil(t, status)
5048

5149
assert.Equal(t, types.StateRunning, status.State)
5250
assert.Equal(t, description, status.Description)
@@ -62,7 +60,6 @@ func TestSetFailedStatus(t *testing.T) {
6260

6361
status, err := manager.GetStatus()
6462
assert.NoError(t, err)
65-
assert.NotNil(t, status)
6663

6764
assert.Equal(t, types.StateFailed, status.State)
6865
assert.Equal(t, description, status.Description)
@@ -96,7 +93,6 @@ func TestSetCompletedStatus(t *testing.T) {
9693

9794
status, err := manager.GetStatus()
9895
assert.NoError(t, err)
99-
assert.NotNil(t, status)
10096

10197
assert.Equal(t, tt.state, status.State)
10298
assert.Equal(t, tt.description, status.Description)

api/internal/store/infra/store.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
const maxLogSize = 100 * 1024 // 100KB total log size
1313

14-
var _ Store = &MemoryStore{}
14+
var _ Store = &memoryStore{}
1515

1616
// Store provides methods for storing and retrieving infrastructure state
1717
type Store interface {
@@ -25,23 +25,23 @@ type Store interface {
2525
GetLogs() (string, error)
2626
}
2727

28-
// MemoryStore is an in-memory implementation of Store
29-
type MemoryStore struct {
28+
// memoryStore is an in-memory implementation of Store
29+
type memoryStore struct {
3030
infra types.Infra
3131
mu sync.RWMutex
3232
}
3333

34-
type StoreOption func(*MemoryStore)
34+
type StoreOption func(*memoryStore)
3535

3636
func WithInfra(infra types.Infra) StoreOption {
37-
return func(s *MemoryStore) {
37+
return func(s *memoryStore) {
3838
s.infra = infra
3939
}
4040
}
4141

4242
// NewMemoryStore creates a new memory store
4343
func NewMemoryStore(opts ...StoreOption) Store {
44-
s := &MemoryStore{}
44+
s := &memoryStore{}
4545

4646
for _, opt := range opts {
4747
opt(s)
@@ -50,7 +50,7 @@ func NewMemoryStore(opts ...StoreOption) Store {
5050
return s
5151
}
5252

53-
func (s *MemoryStore) Get() (types.Infra, error) {
53+
func (s *memoryStore) Get() (types.Infra, error) {
5454
s.mu.RLock()
5555
defer s.mu.RUnlock()
5656

@@ -62,7 +62,7 @@ func (s *MemoryStore) Get() (types.Infra, error) {
6262
return infra, nil
6363
}
6464

65-
func (s *MemoryStore) GetStatus() (types.Status, error) {
65+
func (s *memoryStore) GetStatus() (types.Status, error) {
6666
s.mu.RLock()
6767
defer s.mu.RUnlock()
6868

@@ -74,14 +74,14 @@ func (s *MemoryStore) GetStatus() (types.Status, error) {
7474
return status, nil
7575
}
7676

77-
func (s *MemoryStore) SetStatus(status types.Status) error {
77+
func (s *memoryStore) SetStatus(status types.Status) error {
7878
s.mu.Lock()
7979
defer s.mu.Unlock()
8080
s.infra.Status = status
8181
return nil
8282
}
8383

84-
func (s *MemoryStore) SetStatusDesc(desc string) error {
84+
func (s *memoryStore) SetStatusDesc(desc string) error {
8585
s.mu.Lock()
8686
defer s.mu.Unlock()
8787

@@ -93,7 +93,7 @@ func (s *MemoryStore) SetStatusDesc(desc string) error {
9393
return nil
9494
}
9595

96-
func (s *MemoryStore) RegisterComponent(name string) error {
96+
func (s *memoryStore) RegisterComponent(name string) error {
9797
s.mu.Lock()
9898
defer s.mu.Unlock()
9999

@@ -109,7 +109,7 @@ func (s *MemoryStore) RegisterComponent(name string) error {
109109
return nil
110110
}
111111

112-
func (s *MemoryStore) SetComponentStatus(name string, status types.Status) error {
112+
func (s *memoryStore) SetComponentStatus(name string, status types.Status) error {
113113
s.mu.Lock()
114114
defer s.mu.Unlock()
115115

@@ -123,7 +123,7 @@ func (s *MemoryStore) SetComponentStatus(name string, status types.Status) error
123123
return fmt.Errorf("component %s not found", name)
124124
}
125125

126-
func (s *MemoryStore) AddLogs(logs string) error {
126+
func (s *memoryStore) AddLogs(logs string) error {
127127
s.mu.Lock()
128128
defer s.mu.Unlock()
129129

@@ -135,7 +135,7 @@ func (s *MemoryStore) AddLogs(logs string) error {
135135
return nil
136136
}
137137

138-
func (s *MemoryStore) GetLogs() (string, error) {
138+
func (s *memoryStore) GetLogs() (string, error) {
139139
s.mu.RLock()
140140
defer s.mu.RUnlock()
141141
return s.infra.Logs, nil

api/internal/store/infra/store_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ func TestNewMemoryStore(t *testing.T) {
2828
assert.NotNil(t, store)
2929
infra, err := store.Get()
3030
require.NoError(t, err)
31-
assert.NotNil(t, infra)
32-
assert.NotNil(t, infra.Status)
3331
assert.Equal(t, types.StatePending, infra.Status.State)
3432
}
3533

@@ -185,8 +183,6 @@ func TestMemoryStore_Get(t *testing.T) {
185183
// Test getting infra
186184
infra, err := store.Get()
187185
require.NoError(t, err)
188-
assert.NotNil(t, infra)
189-
assert.NotNil(t, infra.Status)
190186
assert.Empty(t, infra.Components)
191187
assert.Empty(t, infra.Logs)
192188

@@ -293,7 +289,7 @@ func TestMemoryStore_ConcurrentAccess(t *testing.T) {
293289
}
294290

295291
func TestMemoryStore_StatusDescWithoutStatus(t *testing.T) {
296-
store := &MemoryStore{
292+
store := &memoryStore{
297293
infra: types.Infra{},
298294
}
299295

api/internal/store/installation/store.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/tiendc/go-deepcopy"
88
)
99

10-
var _ Store = &MemoryStore{}
10+
var _ Store = &memoryStore{}
1111

1212
type Store interface {
1313
GetConfig() (types.InstallationConfig, error)
@@ -16,21 +16,21 @@ type Store interface {
1616
SetStatus(status types.Status) error
1717
}
1818

19-
type MemoryStore struct {
19+
type memoryStore struct {
2020
mu sync.RWMutex
2121
installation types.Installation
2222
}
2323

24-
type StoreOption func(*MemoryStore)
24+
type StoreOption func(*memoryStore)
2525

2626
func WithInstallation(installation types.Installation) StoreOption {
27-
return func(s *MemoryStore) {
27+
return func(s *memoryStore) {
2828
s.installation = installation
2929
}
3030
}
3131

32-
func NewMemoryStore(opts ...StoreOption) *MemoryStore {
33-
s := &MemoryStore{}
32+
func NewMemoryStore(opts ...StoreOption) *memoryStore {
33+
s := &memoryStore{}
3434

3535
for _, opt := range opts {
3636
opt(s)
@@ -39,7 +39,7 @@ func NewMemoryStore(opts ...StoreOption) *MemoryStore {
3939
return s
4040
}
4141

42-
func (s *MemoryStore) GetConfig() (types.InstallationConfig, error) {
42+
func (s *memoryStore) GetConfig() (types.InstallationConfig, error) {
4343
s.mu.RLock()
4444
defer s.mu.RUnlock()
4545

@@ -51,15 +51,15 @@ func (s *MemoryStore) GetConfig() (types.InstallationConfig, error) {
5151
return config, nil
5252
}
5353

54-
func (s *MemoryStore) SetConfig(cfg types.InstallationConfig) error {
54+
func (s *memoryStore) SetConfig(cfg types.InstallationConfig) error {
5555
s.mu.Lock()
5656
defer s.mu.Unlock()
5757

5858
s.installation.Config = cfg
5959
return nil
6060
}
6161

62-
func (s *MemoryStore) GetStatus() (types.Status, error) {
62+
func (s *memoryStore) GetStatus() (types.Status, error) {
6363
s.mu.RLock()
6464
defer s.mu.RUnlock()
6565

@@ -71,7 +71,7 @@ func (s *MemoryStore) GetStatus() (types.Status, error) {
7171
return status, nil
7272
}
7373

74-
func (s *MemoryStore) SetStatus(status types.Status) error {
74+
func (s *memoryStore) SetStatus(status types.Status) error {
7575
s.mu.Lock()
7676
defer s.mu.Unlock()
7777
s.installation.Status = status

api/internal/store/installation/store_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func TestNewMemoryStore(t *testing.T) {
1414
store := NewMemoryStore(WithInstallation(inst))
1515

1616
assert.NotNil(t, store)
17-
assert.NotNil(t, store.installation)
1817
assert.Equal(t, inst, store.installation)
1918
}
2019

@@ -30,7 +29,6 @@ func TestMemoryStore_GetConfig(t *testing.T) {
3029
config, err := store.GetConfig()
3130

3231
require.NoError(t, err)
33-
assert.NotNil(t, config)
3432
assert.Equal(t, types.InstallationConfig{
3533
AdminConsolePort: 8080,
3634
DataDirectory: "/some/dir",
@@ -72,7 +70,6 @@ func TestMemoryStore_GetStatus(t *testing.T) {
7270
status, err := store.GetStatus()
7371

7472
require.NoError(t, err)
75-
assert.NotNil(t, status)
7673
assert.Equal(t, types.Status{
7774
State: "failed",
7875
Description: "Failure",

0 commit comments

Comments
 (0)