Skip to content

Commit

Permalink
Add test case to cover basic ephemeral storage use
Browse files Browse the repository at this point in the history
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
  • Loading branch information
amisevsk committed Jul 15, 2021
1 parent af3c48d commit dc70ba8
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pkg/provision/storage/ephemeralStorage_test.go
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")
}
})
}
}
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: {}

0 comments on commit dc70ba8

Please sign in to comment.