Skip to content

Commit

Permalink
Update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
thbkrkr committed Oct 19, 2021
1 parent 9d50619 commit f47c3a2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
66 changes: 38 additions & 28 deletions pkg/controller/elasticsearch/license/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,60 +235,70 @@ func Test_applyLinkedLicense(t *testing.T) {

func Test_checkEsLicense(t *testing.T) {
tests := []struct {
name string
wantErr bool
supported bool
updater esclient.LicenseClient
name string
wantErr bool
supported bool
esReachable bool
updater esclient.LicenseClient
}{
{
name: "happy path",
wantErr: false,
supported: true,
name: "happy path",
wantErr: false,
supported: true,
esReachable: true,
updater: &fakeInvalidLicenseUpdater{
fakeLicenseUpdater: &fakeLicenseUpdater{license: esclient.License{Type: string(esclient.ElasticsearchLicenseTypeBasic)}},
statusCodeOnGetLicense: 200,
},
},
{
name: "error: 400 on get license, unsupported distribution",
wantErr: true,
supported: false,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 400},
name: "error: 400 on get license, unsupported distribution",
wantErr: true,
supported: false,
esReachable: true,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 400},
},
{
name: "error: 401 on get license",
wantErr: true,
supported: true,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 401},
name: "error: 401 on get license",
wantErr: true,
supported: true,
esReachable: true,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 401},
},
{
name: "error: 403 on get license",
wantErr: true,
supported: true,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 403},
name: "error: 403 on get license",
wantErr: true,
supported: true,
esReachable: true,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 403},
},
{
name: "error: 404 on get license",
wantErr: true,
supported: true,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 404},
name: "error: 404 on get license",
wantErr: true,
supported: true,
esReachable: true,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 404},
},
{
name: "error: 500 on get license",
wantErr: true,
supported: true,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 500},
name: "error: 500 on get license",
wantErr: true,
supported: true,
esReachable: false,
updater: &fakeInvalidLicenseUpdater{statusCodeOnGetLicense: 500},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, supported, err := checkElasticsearchLicense(context.Background(), tt.updater)
_, supported, esReachable, err := CheckElasticsearchLicense(context.Background(), tt.updater)
if (err != nil) != tt.wantErr {
t.Errorf("checkElasticsearchLicense() error = %v, wantErr %v", err, tt.wantErr)
}
if supported != tt.supported {
t.Errorf("checkElasticsearchLicense() supported = %v, supported %v", supported, tt.supported)
}
if esReachable != tt.esReachable {
t.Errorf("checkElasticsearchLicense() esReachable = %v, esReachable %v", esReachable, tt.esReachable)
}
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ func TestUpdateSettings(t *testing.T) {
record.NewFakeRecorder(100),
tt.args.licenseChecker,
*tt.args.es,
true,
)
if (err != nil) != tt.wantErr {
t.Errorf("UpdateRemoteClusterSettings() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit f47c3a2

Please sign in to comment.