Skip to content

Commit

Permalink
Refactor yaml command test case contexts
Browse files Browse the repository at this point in the history
Introduce intermediate contexts for yaml command test cases for readability.
  • Loading branch information
HeavyWombat committed Feb 19, 2021
1 parent b869fe7 commit c2f1e58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
Empty file.
61 changes: 35 additions & 26 deletions internal/cmd/cmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,57 @@ var _ = Describe("command line tool flags", func() {
})

Context("yaml command", func() {
It("should write a YAML file in place using restructure feature", func() {
filename := createTestFile(`---
Context("using restructure", func() {
Context("to write the file to STDOUT", func() {
It("should write a YAML file to STDOUT using restructure feature", func() {
filename := createTestFile(`---
list:
- aaa: bbb
name: one
`)
defer os.Remove(filename)
defer os.Remove(filename)

out, err := dyff("yaml", "--restructure", "--in-place", filename)
Expect(err).ToNot(HaveOccurred())
Expect(out).To(BeEmpty())
out, err := dyff("yaml", "--restructure", filename)
Expect(err).ToNot(HaveOccurred())
Expect(out).To(BeEquivalentTo(`---
list:
- name: one
aaa: bbb
data, err := ioutil.ReadFile(filename)
Expect(err).To(BeNil())
Expect(string(data)).To(BeEquivalentTo(`list:
- name: one
aaa: bbb
`))
})
})
})

It("should write a YAML file to STDOUT using restructure feature", func() {
filename := createTestFile(`---
Context("to write the file in-place", func() {
It("should write a YAML file in place using restructure feature", func() {
filename := createTestFile(`---
list:
- aaa: bbb
name: one
`)
defer os.Remove(filename)
defer os.Remove(filename)

out, err := dyff("yaml", "--restructure", filename)
Expect(err).ToNot(HaveOccurred())
Expect(out).To(BeEquivalentTo(`---
list:
- name: one
aaa: bbb
out, err := dyff("yaml", "--restructure", "--in-place", filename)
Expect(err).ToNot(HaveOccurred())
Expect(out).To(BeEmpty())

data, err := ioutil.ReadFile(filename)
Expect(err).To(BeNil())
Expect(string(data)).To(BeEquivalentTo(`list:
- name: one
aaa: bbb
`))
})

It("should fail to write a YAML when in place and STDIN are used at the same time", func() {
_, err := dyff("yaml", "--in-place", "-")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(BeEquivalentTo("incompatible flags: cannot use in-place flag in combination with input from STDIN"))
})
})

Context("incorrect usage", func() {
It("should fail to write a YAML when in place and STDIN are used at the same time", func() {
_, err := dyff("yaml", "--in-place", "-")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(BeEquivalentTo("incompatible flags: cannot use in-place flag in combination with input from STDIN"))
})
})
})
})

Expand Down

0 comments on commit c2f1e58

Please sign in to comment.