-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Utkarsh Bhatt <utkarsh.bhatt@canonical.com>
- Loading branch information
1 parent
291c10d
commit ae46a9f
Showing
2 changed files
with
239 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package ceph | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/canonical/microceph/microceph/database" | ||
"github.com/canonical/microceph/microceph/mocks" | ||
"github.com/canonical/microcluster/state" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type ClientConfigSuite struct { | ||
BaseSuite | ||
TestStateInterface *mocks.StateInterface | ||
} | ||
|
||
func TestClientConfig(t *testing.T) { | ||
suite.Run(t, new(ClientConfigSuite)) | ||
} | ||
|
||
func (ccs *ClientConfigSuite) SetupTest() { | ||
ccs.BaseSuite.SetupTest() | ||
|
||
ccs.TestStateInterface = mocks.NewStateInterface(ccs.T()) | ||
state := &state.State{} | ||
|
||
ccs.TestStateInterface.On("ClusterState").Return(state) | ||
} | ||
|
||
func addGetHostConfigsExpectation(mci *mocks.ClientConfigQueryIntf, cs *state.State, hostname string) { | ||
output := database.ClientConfigItems{} | ||
count := 0 | ||
for configKey, field := range GetClientConfigSet() { | ||
count++ | ||
output = append(output, database.ClientConfigItem{ | ||
ID: count, | ||
Host: hostname, | ||
Key: configKey, | ||
Value: fmt.Sprintf("%v", field), | ||
}) | ||
} | ||
|
||
mci.On("GetAllForHost", cs, hostname).Return(output, nil) | ||
} | ||
|
||
func (ccs *ClientConfigSuite) TestFetchHostConfig() { | ||
hostname := "testHostname" | ||
|
||
// Mock Client config query interface. | ||
ccq := mocks.NewClientConfigQueryIntf(ccs.T()) | ||
addGetHostConfigsExpectation(ccq, ccs.TestStateInterface.ClusterState(), hostname) | ||
database.ClientConfigQuery = ccq | ||
|
||
configs, err := GetClientConfigForHost(ccs.TestStateInterface, hostname) | ||
assert.NoError(ccs.T(), err) | ||
|
||
// check fields | ||
metaConfigs := reflect.ValueOf(configs) | ||
for i := 0; i < metaConfigs.NumField(); i++ { | ||
assert.Equal(ccs.T(), metaConfigs.Field(i).Interface(), metaConfigs.Type().Field(i).Name) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.