Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from internal fs to afero fs #146

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/devfile/parser/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"io"

"github.com/devfile/library/pkg/testingutil/filesystem"
"github.com/devfile/library/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/afero"
"gopkg.in/yaml.v3"
k8yaml "sigs.k8s.io/yaml"

Expand Down Expand Up @@ -39,7 +39,7 @@ type KubernetesResources struct {
// It returns all the parsed Kubernetes objects as an array of interface.
// Consumers interested in the Kubernetes resources are expected to Unmarshal
// it to the struct of the respective Kubernetes resource.
func ReadKubernetesYaml(src YamlSrc, fs filesystem.Filesystem) ([]interface{}, error) {
func ReadKubernetesYaml(src YamlSrc, fs afero.Afero) ([]interface{}, error) {

var data []byte
var err error
Expand Down
18 changes: 9 additions & 9 deletions pkg/devfile/parser/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"reflect"
"testing"

"github.com/devfile/library/pkg/testingutil/filesystem"
"github.com/devfile/library/pkg/util"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
)

func TestReadAndParseKubernetesYaml(t *testing.T) {
const serverIP = "127.0.0.1:9080"
var data []byte

fs := filesystem.DefaultFs{}
fs := afero.Afero{Fs: afero.NewOsFs()}
absPath, err := util.GetAbsPath("../../../tests/yamls/resources.yaml")
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestReadAndParseKubernetesYaml(t *testing.T) {
tests := []struct {
name string
src YamlSrc
fs filesystem.Filesystem
fs afero.Afero
wantErr bool
wantDeploymentNames []string
wantServiceNames []string
Expand All @@ -69,7 +69,7 @@ func TestReadAndParseKubernetesYaml(t *testing.T) {
src: YamlSrc{
URL: "http://" + serverIP,
},
fs: filesystem.DefaultFs{},
fs: fs,
wantDeploymentNames: []string{"deploy-sample", "deploy-sample-2"},
wantServiceNames: []string{"service-sample", "service-sample-2"},
wantRouteNames: []string{"route-sample", "route-sample-2"},
Expand All @@ -81,7 +81,7 @@ func TestReadAndParseKubernetesYaml(t *testing.T) {
src: YamlSrc{
Path: "../../../tests/yamls/resources.yaml",
},
fs: filesystem.DefaultFs{},
fs: fs,
wantDeploymentNames: []string{"deploy-sample", "deploy-sample-2"},
wantServiceNames: []string{"service-sample", "service-sample-2"},
wantRouteNames: []string{"route-sample", "route-sample-2"},
Expand All @@ -93,7 +93,7 @@ func TestReadAndParseKubernetesYaml(t *testing.T) {
src: YamlSrc{
Data: data,
},
fs: filesystem.DefaultFs{},
fs: fs,
wantDeploymentNames: []string{"deploy-sample", "deploy-sample-2"},
wantServiceNames: []string{"service-sample", "service-sample-2"},
wantRouteNames: []string{"route-sample", "route-sample-2"},
Expand All @@ -105,23 +105,23 @@ func TestReadAndParseKubernetesYaml(t *testing.T) {
src: YamlSrc{
URL: "http://badurl",
},
fs: filesystem.DefaultFs{},
fs: fs,
wantErr: true,
},
{
name: "Bad Path",
src: YamlSrc{
Path: "$%^&",
},
fs: filesystem.DefaultFs{},
fs: fs,
wantErr: true,
},
{
name: "Bad Data",
src: YamlSrc{
Data: badData,
},
fs: filesystem.DefaultFs{},
fs: fs,
wantErr: true,
},
}
Expand Down