Skip to content

Commit

Permalink
fix: fixes to indentation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanSpeakEasy committed Feb 27, 2023
1 parent b6e86b0 commit 6be26d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions io.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"bufio"
"bytes"
"errors"
"fmt"
"io/fs"
Expand Down Expand Up @@ -166,11 +168,21 @@ func findConfigFile(dir string, o *options) ([]byte, string, error) {
}

func write(path string, cfg any, o *options) ([]byte, error) {
data, err := yaml.Marshal(cfg)
if err != nil {
var b bytes.Buffer
buf := bufio.NewWriter(&b)

e := yaml.NewEncoder(buf)
e.SetIndent(2)
if err := e.Encode(cfg); err != nil {
return nil, fmt.Errorf("could not marshal gen.yaml: %w", err)
}

if err := buf.Flush(); err != nil {
return nil, fmt.Errorf("could not marshal gen.yaml: %w", err)
}

data := b.Bytes()

if err := o.writeFileFunc(path, data, os.ModePerm); err != nil {
return nil, fmt.Errorf("could not write gen.yaml: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestLoad_Success(t *testing.T) {
Generation: Generation{
SDKClassName: "SDK",
TelemetryEnabled: false,
SDKFlattening: true,
},
},
},
Expand Down Expand Up @@ -67,6 +68,7 @@ func TestLoad_Success(t *testing.T) {
Comments: &Comments{
OmitDescriptionIfSummaryPresent: true,
},
SDKFlattening: false,
},
},
},
Expand Down Expand Up @@ -98,6 +100,7 @@ func TestLoad_Success(t *testing.T) {
Comments: &Comments{
OmitDescriptionIfSummaryPresent: true,
},
SDKFlattening: false,
},
},
},
Expand Down Expand Up @@ -129,6 +132,7 @@ func TestLoad_Success(t *testing.T) {
Comments: &Comments{
OmitDescriptionIfSummaryPresent: true,
},
SDKFlattening: false,
},
},
},
Expand Down

0 comments on commit 6be26d4

Please sign in to comment.