Skip to content

Commit

Permalink
test: newlines on formatted files (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcreey committed Apr 17, 2024
1 parent 4f6b697 commit 5e26b0f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,14 @@ func Test_loadYAMLFiles(t *testing.T) {
name string
yamlFilenames []string
format bool
fixNewlines bool
want string
}{
{
name: "yamlA_multiple_empty_lines",
yamlFilenames: []string{"testdata/github.yml"},
format: false,
fixNewlines: false,
want: `jobs:
my_job:
runs-on: 'ubuntu-latest'
Expand Down Expand Up @@ -365,6 +367,7 @@ func Test_loadYAMLFiles(t *testing.T) {
name: "handles-leading-dot-slash",
yamlFilenames: []string{"./testdata/github.yml"},
format: false,
fixNewlines: false,
want: `jobs:
my_job:
runs-on: 'ubuntu-latest'
Expand Down Expand Up @@ -394,27 +397,35 @@ func Test_loadYAMLFiles(t *testing.T) {
name: "yaml_steps_indent_change",
yamlFilenames: []string{"testdata/github.yml"},
format: true,
fixNewlines: true,
want: `jobs:
my_job:
runs-on: 'ubuntu-latest'
container:
image: 'ubuntu:20.04'
services:
nginx:
image: 'nginx:1.21'
steps:
- uses: 'actions/checkout@v3'
- uses: 'docker://ubuntu:20.04'
with:
uses: '/path/to/user.png'
image: '/path/to/image.jpg'
- runs: |-
echo "Hello 😀"
if [ "true" == "false" ];
echo "NOPE"
fi
other_job:
uses: 'my-org/my-repo/.github/workflows/my-workflow.yml@v0'
final_job:
uses: './local/path/to/action'
`,
Expand All @@ -423,27 +434,35 @@ func Test_loadYAMLFiles(t *testing.T) {
name: "yaml_all_indent_change",
yamlFilenames: []string{"testdata/github-crazy-indent.yml"},
format: true,
fixNewlines: true,
want: `jobs:
my_job:
runs-on: 'ubuntu-latest'
container:
image: 'ubuntu:20.04'
services:
nginx:
image: 'nginx:1.21'
steps:
- uses: 'actions/checkout@v3'
- uses: 'docker://ubuntu:20.04'
with:
uses: '/path/to/user.png'
image: '/path/to/image.jpg'
- runs: |-
echo "Hello 😀"
if [ "true" == "false" ];
echo "NOPE"
fi
other_job:
uses: 'my-org/my-repo/.github/workflows/my-workflow.yml@v0'
final_job:
uses: './local/path/to/action'
`,
Expand All @@ -466,6 +485,9 @@ func Test_loadYAMLFiles(t *testing.T) {
t.Fatalf("marshalYAML() returned error: %s", err)
}
got := string(b)
if tc.fixNewlines {
got = removeNewLineChanges(string(files[0].contents), got)
}

if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("returned diff (-want, +got):\n%s", diff)
Expand Down

0 comments on commit 5e26b0f

Please sign in to comment.