-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
341 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package commands | ||
package apply | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package apply | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/teran/cephctl/models" | ||
"github.com/teran/cephctl/service" | ||
) | ||
|
||
func TestApply(t *testing.T) { | ||
r := require.New(t) | ||
|
||
m := service.NewMock() | ||
defer m.AssertExpectations(t) | ||
|
||
m.On("ApplyCephConfig", models.CephConfig{ | ||
"global": { | ||
"test": "value", | ||
}, | ||
}).Return(nil).Once() | ||
|
||
err := Apply(context.Background(), ApplyConfig{ | ||
Service: m, | ||
SpecFile: "testdata/cephconfig.yaml", | ||
}) | ||
r.NoError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
kind: CephConfig | ||
spec: | ||
global: | ||
test: value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package diff | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/teran/cephctl/models" | ||
"github.com/teran/cephctl/printer" | ||
"github.com/teran/cephctl/service" | ||
"github.com/teran/go-ptr" | ||
) | ||
|
||
func TestDiff(t *testing.T) { | ||
r := require.New(t) | ||
|
||
m := service.NewMock() | ||
defer m.AssertExpectations(t) | ||
|
||
p := printer.NewMock() | ||
defer p.AssertExpectations(t) | ||
|
||
m.On("DiffCephConfig", models.CephConfig{ | ||
"global": { | ||
"test": "value", | ||
}, | ||
}).Return([]models.CephConfigDifference{ | ||
{ | ||
Kind: models.CephConfigDifferenceKindAdd, | ||
Section: "mon", | ||
Key: "test_key", | ||
Value: ptr.String("value"), | ||
}, | ||
{ | ||
Kind: models.CephConfigDifferenceKindChange, | ||
Section: "osd.3", | ||
Key: "test_key", | ||
OldValue: ptr.String("old_value"), | ||
Value: ptr.String("value"), | ||
}, | ||
{ | ||
Kind: models.CephConfigDifferenceKindRemove, | ||
Section: "osd", | ||
Key: "test_key", | ||
}, | ||
}, nil).Once() | ||
|
||
p.On("Green", "+ %s %s %s", []any{"mon", "test_key", "value"}).Return().Once() | ||
p.On("Yellow", "~ %s %s %s -> %s", []any{"osd.3", "test_key", "old_value", "value"}).Return().Once() | ||
p.On("Red", "- %s %s", []any{"osd", "test_key"}).Return().Once() | ||
|
||
err := Diff(context.Background(), DiffConfig{ | ||
Printer: p, | ||
Service: m, | ||
SpecFile: "testdata/cephconfig.yaml", | ||
}) | ||
r.NoError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
kind: CephConfig | ||
spec: | ||
global: | ||
test: value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cephconfig | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/teran/cephctl/models" | ||
"github.com/teran/cephctl/printer" | ||
"github.com/teran/cephctl/service" | ||
) | ||
|
||
func TestDumpCephConfig(t *testing.T) { | ||
r := require.New(t) | ||
|
||
m := service.NewMock() | ||
defer m.AssertExpectations(t) | ||
|
||
p := printer.NewMock() | ||
defer p.AssertExpectations(t) | ||
|
||
m.On("DumpConfig").Return(models.CephConfig{ | ||
"global": { | ||
"key": "value", | ||
}, | ||
}, nil).Once() | ||
|
||
p.On("Println", []any{"kind: CephConfig\nspec:\n global:\n key: value\n"}).Return().Once() | ||
|
||
err := DumpCephConfig(context.Background(), DumpCephConfigConfig{ | ||
Printer: p, | ||
Service: m, | ||
}) | ||
r.NoError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package healthcheck | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/teran/cephctl/models" | ||
"github.com/teran/cephctl/printer" | ||
"github.com/teran/cephctl/service" | ||
) | ||
|
||
func TestHealthcheck(t *testing.T) { | ||
r := require.New(t) | ||
|
||
m := service.NewMock() | ||
defer m.AssertExpectations(t) | ||
|
||
p := printer.NewMock() | ||
defer p.AssertExpectations(t) | ||
|
||
m.On("CheckClusterHealth").Return([]models.ClusterHealthIndicator{ | ||
{ | ||
Indicator: models.ClusterHealthIndicatorTypeClusterStatus, | ||
CurrentValue: "HEALTH_OK", | ||
CurrentValueStatus: models.ClusterHealthIndicatorStatusGood, | ||
}, | ||
{ | ||
Indicator: models.ClusterHealthIndicatorTypeQuorum, | ||
CurrentValue: "5 of 5", | ||
CurrentValueStatus: models.ClusterHealthIndicatorStatusGood, | ||
}, | ||
{ | ||
Indicator: models.ClusterHealthIndicatorTypeOSDsDown, | ||
CurrentValue: "0 of 15", | ||
CurrentValueStatus: models.ClusterHealthIndicatorStatusGood, | ||
}, | ||
}, nil).Once() | ||
|
||
p.On("Green", "[%s] %s = %s", []any{ | ||
" GOOD", models.ClusterHealthIndicatorTypeClusterStatus, "HEALTH_OK", | ||
}).Return().Once() | ||
p.On("Green", "[%s] %s = %s", []any{ | ||
" GOOD", models.ClusterHealthIndicatorTypeQuorum, "5 of 5", | ||
}).Return().Once() | ||
p.On("Green", "[%s] %s = %s", []any{ | ||
" GOOD", models.ClusterHealthIndicatorTypeOSDsDown, "0 of 15", | ||
}).Return().Once() | ||
|
||
err := Healthcheck(context.Background(), HealthcheckConfig{ | ||
Printer: p, | ||
Service: m, | ||
}) | ||
r.NoError(err) | ||
} |
Oops, something went wrong.