Skip to content

Commit

Permalink
[#83] change File.Data field: string -> []byte
Browse files Browse the repository at this point in the history
  • Loading branch information
kozmod committed Jun 3, 2023
1 parent eed1fe3 commit e3c64a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"golang.org/x/xerrors"
"gopkg.in/yaml.v3"

"github.com/kozmod/progen/internal/entity"
)
Expand Down Expand Up @@ -43,11 +44,18 @@ type Section[T any] struct {

type File struct {
Path string `yaml:"path"`
Data *string `yaml:"data"`
Data *Bytes `yaml:"data"`
Get *Get `yaml:"get"`
Local *string `yaml:"local"`
}

type Bytes []byte

func (fd *Bytes) UnmarshalYAML(node *yaml.Node) error {
*fd = Bytes(node.Value)
return nil
}

type Command struct {
Dir string `yaml:"dir"`
Exec string `yaml:"exec"`
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func Test_ValidateFile(t *testing.T) {
t.Run("not_error_when_data_is_not_nil", func(t *testing.T) {
in := File{
Path: path,
Data: func(s string) *string { return &s }("some data"),
Data: func(d Bytes) *Bytes { return &d }(Bytes("some data")),
Get: nil,
}
err := ValidateFile(in)
Expand All @@ -144,7 +144,7 @@ func Test_ValidateFile(t *testing.T) {
t.Run("error_when_data_and_get_are_not_nil_both", func(t *testing.T) {
in := File{
Path: path,
Data: func(s string) *string { return &s }("some data"),
Data: func(d Bytes) *Bytes { return &d }(Bytes("some data")),
Get: &Get{},
}
err := ValidateFile(in)
Expand Down Expand Up @@ -272,7 +272,7 @@ cmd2:
file := files.Val[0]
a.Equal("x/DDDDDD", file.Path)
a.NotNil(file.Data)
a.Equal("ENV GOPROXY \"{{.vars.GOPROXY}} ,proxy.golang.org,direct\"\n", *file.Data)
a.Equal(Bytes("ENV GOPROXY \"{{.vars.GOPROXY}} ,proxy.golang.org,direct\"\n"), *file.Data)
})

t.Run("success_unmarshal_skip_all_cmd_and_dirs2_sections", func(t *testing.T) {
Expand Down Expand Up @@ -333,7 +333,7 @@ cmd2:
file := files.Val[0]
a.Equal("x/DDDDDD", file.Path)
a.NotNil(file.Data)
a.Equal("ENV GOPROXY \"{{.vars.GOPROXY}} ,proxy.golang.org,direct\"\n", *file.Data)
a.Equal(Bytes("ENV GOPROXY \"{{.vars.GOPROXY}} ,proxy.golang.org,direct\"\n"), *file.Data)
})
t.Run("error_when-config_not_contains_executable_actions", func(t *testing.T) {
const (
Expand Down
2 changes: 1 addition & 1 deletion internal/factory/file_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewFileExecutor(
case f.Data != nil:
file := entity.DataFile{
FileInfo: tmpl,
Data: []byte(*f.Data),
Data: *f.Data,
}
producer = exec.NewDummyProducer(file)
case f.Get != nil:
Expand Down

0 comments on commit e3c64a1

Please sign in to comment.