-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case to cover basic ephemeral storage use
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
- Loading branch information
Showing
2 changed files
with
118 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,50 @@ | ||
// | ||
// Copyright (c) 2019-2021 Red Hat, Inc. | ||
// This program and the accompanying materials are made | ||
// available under the terms of the Eclipse Public License 2.0 | ||
// which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
// | ||
// Contributors: | ||
// Red Hat, Inc. - initial API and implementation | ||
// | ||
|
||
package storage | ||
|
||
import ( | ||
"testing" | ||
|
||
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/devfile/devworkspace-operator/controllers/workspace/provision" | ||
) | ||
|
||
func TestRewriteContainerVolumeMountsForEphemeralStorageClass(t *testing.T) { | ||
tests := loadAllTestCasesOrPanic(t, "testdata/ephemeral-storage") | ||
setupControllerCfg() | ||
commonStorage := EphemeralStorageProvisioner{} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.Name, func(t *testing.T) { | ||
// sanity check that file is read correctly. | ||
assert.NotNil(t, tt.Input.Workspace, "Input does not define workspace") | ||
workspace := &dw.DevWorkspace{} | ||
workspace.Spec.Template = *tt.Input.Workspace | ||
workspace.Status.DevWorkspaceId = tt.Input.DevWorkspaceID | ||
workspace.Namespace = "test-namespace" | ||
err := commonStorage.ProvisionStorage(&tt.Input.PodAdditions, workspace, provision.ClusterAPI{}) | ||
if tt.Output.ErrRegexp != nil && assert.Error(t, err) { | ||
assert.Regexp(t, *tt.Output.ErrRegexp, err.Error(), "Error message should match") | ||
} else { | ||
if !assert.NoError(t, err, "Should not return error") { | ||
return | ||
} | ||
sortVolumesAndVolumeMounts(&tt.Output.PodAdditions) | ||
sortVolumesAndVolumeMounts(&tt.Input.PodAdditions) | ||
assert.Equal(t, tt.Output.PodAdditions, tt.Input.PodAdditions, "PodAdditions should match expected output") | ||
} | ||
}) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
pkg/provision/storage/testdata/ephemeral-storage/supports-ephemeral-storageclass.yaml
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,68 @@ | ||
name: "Supports ephemeral storageclass" | ||
|
||
input: | ||
devworkspaceId: "test-workspaceid" | ||
podAdditions: | ||
containers: | ||
- name: testing-container-1 | ||
image: testing-image-1 | ||
volumeMounts: | ||
- name: testvol-1 | ||
mountPath: testPath1 | ||
- name: testvol-3 | ||
mountPath: testPath3 | ||
- name: testing-container-2 | ||
image: testing-image-2 | ||
volumeMounts: | ||
- name: testvol-2 | ||
mountPath: testPath2 | ||
- name: "projects" | ||
mountPath: "/projects" | ||
|
||
workspace: | ||
components: | ||
- name: testing-container-1 | ||
container: | ||
image: testing-image-1 | ||
mountSources: false | ||
- name: testing-container-2 | ||
container: | ||
image: testing-image-2 | ||
mountSources: true | ||
|
||
- name: testvol-1 | ||
volume: | ||
ephemeral: true | ||
- name: testvol-2 | ||
volume: | ||
ephemeral: false | ||
- name: testvol-3 | ||
volume: {} | ||
|
||
output: | ||
podAdditions: | ||
containers: | ||
- name: testing-container-1 | ||
image: testing-image-1 | ||
volumeMounts: | ||
- name: testvol-1 | ||
mountPath: testPath1 | ||
- name: testvol-3 | ||
mountPath: testPath3 | ||
- name: testing-container-2 | ||
image: testing-image-2 | ||
volumeMounts: | ||
- name: testvol-2 | ||
mountPath: testPath2 | ||
- name: projects | ||
mountPath: /projects | ||
|
||
volumes: | ||
- name: projects | ||
emptyDir: {} | ||
- name: testvol-1 | ||
emptyDir: {} | ||
- name: testvol-2 | ||
emptyDir: {} | ||
- name: testvol-3 | ||
emptyDir: {} |