Skip to content

Commit

Permalink
add ability to automatically update CLI test case expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
benweint committed May 28, 2024
1 parent d6b6393 commit 52242bf
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 395 deletions.
16 changes: 12 additions & 4 deletions pkg/commands/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
)

type TestCaseParams struct {
Dir string
Args []string `yaml:"args"`
ExpectJson bool `yaml:"expectJson"`
ExpectedOutput string
Dir string
Args []string `yaml:"args"`
ExpectJson bool `yaml:"expectJson"`
ExpectedOutput string
expectedOutputPath string
}

func TestCli(t *testing.T) {
Expand Down Expand Up @@ -46,6 +47,7 @@ func TestCli(t *testing.T) {
}

expectedOutputPath := path.Join(testCaseDir, expectedFilename)
params.expectedOutputPath = expectedOutputPath
expectedOutputRaw, err := os.ReadFile(expectedOutputPath)
assert.NoError(t, err)
params.ExpectedOutput = string(expectedOutputRaw)
Expand All @@ -70,6 +72,12 @@ func TestCli(t *testing.T) {
})
assert.NoError(t, err)

updateExpected := os.Getenv("TEST_UPDATE_EXPECTED")
if updateExpected != "" {
err = os.WriteFile(tc.expectedOutputPath, stdoutBuf.Bytes(), 0655)
assert.NoError(t, err)
}

if tc.ExpectJson {
assert.JSONEq(t, tc.ExpectedOutput, stdoutBuf.String())
} else {
Expand Down
288 changes: 144 additions & 144 deletions pkg/commands/testdata/cases/ls_fields_json/expected.json
Original file line number Diff line number Diff line change
@@ -1,161 +1,161 @@
[
{
"name": "Apple.calories",
"type": {
"kind": "SCALAR",
"name": "Int"
},
"typeName": "Int",
"underlyingTypeName": "Int"
{
"name": "Apple.calories",
"type": {
"kind": "SCALAR",
"name": "Int"
},
{
"name": "Apple.measurements",
"type": {
"kind": "OBJECT",
"name": "Measurements"
},
"typeName": "Measurements",
"underlyingTypeName": "Measurements"
"typeName": "Int",
"underlyingTypeName": "Int"
},
{
"name": "Apple.measurements",
"type": {
"kind": "OBJECT",
"name": "Measurements"
},
{
"name": "Apple.variety",
"type": {
"kind": "ENUM",
"name": "AppleVariety"
},
"typeName": "AppleVariety",
"underlyingTypeName": "AppleVariety"
"typeName": "Measurements",
"underlyingTypeName": "Measurements"
},
{
"name": "Apple.variety",
"type": {
"kind": "ENUM",
"name": "AppleVariety"
},
{
"name": "Biscuit.calories",
"type": {
"kind": "SCALAR",
"name": "Int"
},
"typeName": "Int",
"underlyingTypeName": "Int"
"typeName": "AppleVariety",
"underlyingTypeName": "AppleVariety"
},
{
"name": "Biscuit.calories",
"type": {
"kind": "SCALAR",
"name": "Int"
},
{
"name": "Edible.calories",
"type": {
"kind": "SCALAR",
"name": "Int"
},
"typeName": "Int",
"underlyingTypeName": "Int"
"typeName": "Int",
"underlyingTypeName": "Int"
},
{
"name": "Edible.calories",
"type": {
"kind": "SCALAR",
"name": "Int"
},
{
"name": "Measurements.depth",
"type": {
"kind": "SCALAR",
"name": "Int"
},
"typeName": "Int",
"underlyingTypeName": "Int"
"typeName": "Int",
"underlyingTypeName": "Int"
},
{
"name": "Measurements.depth",
"type": {
"kind": "SCALAR",
"name": "Int"
},
{
"name": "Measurements.height",
"type": {
"kind": "SCALAR",
"name": "Int"
},
"typeName": "Int",
"underlyingTypeName": "Int"
"typeName": "Int",
"underlyingTypeName": "Int"
},
{
"name": "Measurements.height",
"type": {
"kind": "SCALAR",
"name": "Int"
},
{
"name": "Measurements.width",
"type": {
"kind": "SCALAR",
"name": "Int"
},
"typeName": "Int",
"underlyingTypeName": "Int"
"typeName": "Int",
"underlyingTypeName": "Int"
},
{
"name": "Measurements.width",
"type": {
"kind": "SCALAR",
"name": "Int"
},
{
"name": "Orange.calories",
"type": {
"kind": "SCALAR",
"name": "Int"
},
"typeName": "Int",
"underlyingTypeName": "Int"
"typeName": "Int",
"underlyingTypeName": "Int"
},
{
"name": "Orange.calories",
"type": {
"kind": "SCALAR",
"name": "Int"
},
{
"name": "Orange.variety",
"type": {
"kind": "ENUM",
"name": "OrangeVariety"
},
"typeName": "OrangeVariety",
"underlyingTypeName": "OrangeVariety"
"typeName": "Int",
"underlyingTypeName": "Int"
},
{
"name": "Orange.variety",
"type": {
"kind": "ENUM",
"name": "OrangeVariety"
},
{
"arguments": [
{
"name": "name",
"type": {
"kind": "SCALAR",
"name": "String"
},
"typeName": "String",
"underlyingTypeName": "String"
}
],
"name": "Query.edible",
"type": {
"kind": "INTERFACE",
"name": "Edible"
},
"typeName": "Edible",
"underlyingTypeName": "Edible"
"typeName": "OrangeVariety",
"underlyingTypeName": "OrangeVariety"
},
{
"arguments": [
{
"name": "name",
"type": {
"kind": "SCALAR",
"name": "String"
},
"typeName": "String",
"underlyingTypeName": "String"
}
],
"name": "Query.edible",
"type": {
"kind": "INTERFACE",
"name": "Edible"
},
{
"arguments": [
{
"name": "filter",
"type": {
"kind": "INPUT_OBJECT",
"name": "Filter"
},
"typeName": "Filter",
"underlyingTypeName": "Filter"
}
],
"name": "Query.edibles",
"type": {
"kind": "NON_NULL",
"typeName": "Edible",
"underlyingTypeName": "Edible"
},
{
"arguments": [
{
"name": "filter",
"type": {
"kind": "INPUT_OBJECT",
"name": "Filter"
},
"typeName": "Filter",
"underlyingTypeName": "Filter"
}
],
"name": "Query.edibles",
"type": {
"kind": "NON_NULL",
"ofType": {
"kind": "LIST",
"ofType": {
"kind": "LIST",
"kind": "NON_NULL",
"ofType": {
"kind": "NON_NULL",
"ofType": {
"kind": "INTERFACE",
"name": "Edible"
}
"kind": "INTERFACE",
"name": "Edible"
}
}
},
"typeName": "[Edible!]!",
"underlyingTypeName": "Edible"
}
},
{
"arguments": [
{
"name": "name",
"type": {
"kind": "SCALAR",
"name": "String"
},
"typeName": "String",
"underlyingTypeName": "String"
}
],
"name": "Query.fruit",
"type": {
"kind": "UNION",
"name": "Fruit"
},
"typeName": "Fruit",
"underlyingTypeName": "Fruit"
}
]
"typeName": "[Edible!]!",
"underlyingTypeName": "Edible"
},
{
"arguments": [
{
"name": "name",
"type": {
"kind": "SCALAR",
"name": "String"
},
"typeName": "String",
"underlyingTypeName": "String"
}
],
"name": "Query.fruit",
"type": {
"kind": "UNION",
"name": "Fruit"
},
"typeName": "Fruit",
"underlyingTypeName": "Fruit"
}
]
1 change: 1 addition & 0 deletions pkg/commands/testdata/cases/ls_types/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ OBJECT Apple
ENUM AppleVariety
OBJECT Biscuit
INTERFACE Edible
SCALAR FieldSet
INPUT_OBJECT Filter
UNION Fruit
OBJECT Measurements
Expand Down
Loading

0 comments on commit 52242bf

Please sign in to comment.