-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed RKE cluster being shown as Imported (#9868)
- Loading branch information
1 parent
92d8103
commit 6d4f75a
Showing
6 changed files
with
130 additions
and
50 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
28 changes: 0 additions & 28 deletions
28
shell/components/formatter/__tests__/ClusterProvider.test.ts
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
shell/models/__tests__/management.cattle.io.cluster.test.ts
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,19 @@ | ||
import MgmtCluster from '@shell/models/management.cattle.io.cluster'; | ||
|
||
describe('class MgmtCluster', () => { | ||
describe('provisioner', () => { | ||
const testCases = [ | ||
[{ provider: 'rke', driver: 'imported' }, 'rke'], | ||
[{ provider: 'k3s', driver: 'K3S' }, 'k3s'], | ||
[{ provider: 'aks', driver: 'AKS' }, 'aks'], | ||
[{}, 'imported'], | ||
]; | ||
|
||
it.each(testCases)('should return provisioner value properly based on the props data', (clusterData: Object, expected: String) => { | ||
const cluster = new MgmtCluster({ status: clusterData }); | ||
|
||
expect(cluster.provisioner).toBe(expected); | ||
} | ||
); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
shell/models/__tests__/provisioning.cattle.io.cluster.test.ts
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,90 @@ | ||
import ProvCluster from '@shell/models/provisioning.cattle.io.cluster'; | ||
|
||
describe('class ProvCluster', () => { | ||
const importedClusterInfo = { | ||
clusterName: 'test', provisioner: 'imported', mgmt: { spec: { gkeConfig: {} } }, spec: {} | ||
}; | ||
const importedGkeClusterInfo = { | ||
clusterName: 'test', provisioner: 'rke2', mgmt: { spec: { gkeConfig: { imported: true } } } | ||
}; | ||
const importedAksClusterInfo = { | ||
clusterName: 'test', provisioner: 'rke2', mgmt: { spec: { aksConfig: { imported: true } } } | ||
}; | ||
const importedEksClusterInfo = { | ||
clusterName: 'test', provisioner: 'rke2', mgmt: { spec: { eksConfig: { imported: true } } } | ||
}; | ||
const notImportedGkeClusterInfo = { | ||
clusterName: 'test', provisioner: 'rke2', mgmt: { spec: { gkeConfig: { imported: false } }, rkeConfig: {} } | ||
}; | ||
const importedClusterInfoWithProviderForEmberParam = { | ||
clusterName: 'test', provisioner: 'rke2', mgmt: { providerForEmberParam: 'import' } | ||
}; | ||
const localClusterInfo = { | ||
clusterName: 'test', provisioner: 'imported', mgmt: { isLocal: true, spec: { gkeConfig: {} } }, spec: {} | ||
}; | ||
const doRke2Info = { | ||
clusterName: 'test', provisioner: 'rke2', mgmt: { isLocal: false, providerForEmberParam: 'import' }, spec: { rkeConfig: {} } | ||
}; | ||
|
||
describe('isImported', () => { | ||
const testCases = [ | ||
[importedClusterInfo, true], | ||
[importedGkeClusterInfo, true], | ||
[importedAksClusterInfo, true], | ||
[importedEksClusterInfo, true], | ||
[notImportedGkeClusterInfo, false], | ||
[importedClusterInfoWithProviderForEmberParam, true], | ||
[localClusterInfo, false], | ||
[doRke2Info, false], | ||
[{}, false], | ||
]; | ||
const resetMocks = () => { | ||
// Clear all mock function calls: | ||
jest.clearAllMocks(); | ||
}; | ||
|
||
it.each(testCases)('should return the isImported value properly based on the props data', (clusterData: Object, expected: Boolean) => { | ||
const cluster = new ProvCluster({ spec: clusterData.spec }); | ||
|
||
jest.spyOn(cluster, 'mgmt', 'get').mockReturnValue( | ||
clusterData.mgmt | ||
); | ||
jest.spyOn(cluster, 'provisioner', 'get').mockReturnValue( | ||
clusterData.provisioner | ||
); | ||
|
||
expect(cluster.isImported).toBe(expected); | ||
resetMocks(); | ||
} | ||
); | ||
}); | ||
|
||
describe('mgmt', () => { | ||
const testCases = [ | ||
[importedClusterInfo, importedClusterInfo.mgmt], | ||
[importedGkeClusterInfo, importedGkeClusterInfo.mgmt], | ||
[importedAksClusterInfo, importedAksClusterInfo.mgmt], | ||
[importedEksClusterInfo, importedEksClusterInfo.mgmt], | ||
[notImportedGkeClusterInfo, notImportedGkeClusterInfo.mgmt], | ||
[importedClusterInfoWithProviderForEmberParam, importedClusterInfoWithProviderForEmberParam.mgmt], | ||
[localClusterInfo, localClusterInfo.mgmt], | ||
[doRke2Info, doRke2Info.mgmt], | ||
[{}, null], | ||
]; | ||
|
||
const resetMocks = () => { | ||
// Clear all mock function calls: | ||
jest.clearAllMocks(); | ||
}; | ||
|
||
it.each(testCases)('should return the isImported value properly based on the props data', (clusterData: Object, expected: Object) => { | ||
const clusterMock = jest.fn(() => clusterData.mgmt); | ||
const ctx = { rootGetters: { 'management/byId': clusterMock } }; | ||
const cluster = new ProvCluster({ status: { clusterName: clusterData.clusterName } }, ctx); | ||
|
||
expect(cluster.mgmt).toBe(expected); | ||
resetMocks(); | ||
} | ||
); | ||
}); | ||
}); |
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