github.com/tomwright/dasel@v1.27.3/internal/command/root_validate_test.go (about)

     1  package command_test
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestRootCMD_Validate(t *testing.T) {
     8  	t.Run("AllPass", expectOutputAndErr(
     9  		[]string{"validate", "./../../tests/assets/example.json", "./../../tests/assets/example.yaml"},
    10  		"",
    11  		`pass ./../../tests/assets/example.json
    12  pass ./../../tests/assets/example.yaml
    13  `,
    14  	))
    15  
    16  	t.Run("PartialFail", expectOutputAndErr(
    17  		[]string{"validate", "./../../tests/assets/example.json", "./../../tests/assets/example.yaml", "./../../tests/assets/broken.json", "./../../tests/assets/broken.xml"},
    18  		"2 files failed validation",
    19  		`pass ./../../tests/assets/example.json
    20  pass ./../../tests/assets/example.yaml
    21  fail ./../../tests/assets/broken.json could not load input: could not unmarshal data: invalid character '}' after array element
    22  fail ./../../tests/assets/broken.xml could not load input: could not unmarshal data: xml.Decoder.Token() - XML syntax error on line 1: element <a> closed by </b>
    23  `,
    24  	))
    25  
    26  	t.Run("PartialGlob", expectOutputAndErr(
    27  		[]string{"validate", "./../../tests/assets/*.json"},
    28  		"1 files failed validation",
    29  		`fail ../../tests/assets/broken.json could not load input: could not unmarshal data: invalid character '}' after array element
    30  pass ../../tests/assets/example.json
    31  pass ../../tests/assets/json-value.json
    32  `,
    33  	))
    34  
    35  	t.Run("AllFail", expectOutputAndErr(
    36  		[]string{"validate", "./../../tests/assets/broken.json", "./../../tests/assets/broken.xml"},
    37  		"2 files failed validation",
    38  		`fail ./../../tests/assets/broken.json could not load input: could not unmarshal data: invalid character '}' after array element
    39  fail ./../../tests/assets/broken.xml could not load input: could not unmarshal data: xml.Decoder.Token() - XML syntax error on line 1: element <a> closed by </b>
    40  `,
    41  	))
    42  
    43  	t.Run("AllFailNoErrors", expectOutputAndErr(
    44  		[]string{"validate", "--include-error=false", "./../../tests/assets/broken.json", "./../../tests/assets/broken.xml"},
    45  		"2 files failed validation",
    46  		`fail ./../../tests/assets/broken.json
    47  fail ./../../tests/assets/broken.xml
    48  `,
    49  	))
    50  
    51  	t.Run("NoFilesPass", expectOutputAndErr(
    52  		[]string{"validate"},
    53  		"",
    54  		``,
    55  	))
    56  }