forked from go-swagger/go-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration for minimal flatten mode
* Fixes go-swagger#1572 Contents: * Enables new swagger CLI options to flatten minimally, fully or expand. Minimal flatten is the default. * Deprecates --skip-flatten option (replaced by --with-expand) And also: * Adapted tests to reflect this new default * Refactored schema building in operations for body parameters and responses * More UTs * Again some more linting * Cyclo check level for golangCI pushed to 25 * Removed -race option from appveyor CI * Fix bug with deep maps (rewind ValueExpression) * Setup parallel testing for models
- Loading branch information
Showing
59 changed files
with
2,384 additions
and
12,039 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package commands | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
flags "github.com/jessevdk/go-flags" | ||
) | ||
|
||
// Commands requires at least one arg | ||
func TestCmd_Expand(t *testing.T) { | ||
v := &ExpandSpec{} | ||
testRequireParam(t, v) | ||
} | ||
|
||
func TestCmd_Expand_NoError(t *testing.T) { | ||
specDoc := filepath.Join(fixtureBase, "bugs", "1536", "fixture-1536.yaml") | ||
outDir, output := getOutput(t, specDoc, "flatten", "fixture-1536-flat-expand.json") | ||
defer os.RemoveAll(outDir) | ||
v := &ExpandSpec{ | ||
Format: "json", | ||
Compact: false, | ||
Output: flags.Filename(output), | ||
} | ||
testProduceOutput(t, v, specDoc, output) | ||
} | ||
|
||
func TestCmd_Expand_Error(t *testing.T) { | ||
v := &ExpandSpec{} | ||
testValidRefs(t, v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package commands | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
flags "github.com/jessevdk/go-flags" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type executable interface { | ||
Execute([]string) error | ||
} | ||
|
||
func testValidRefs(t *testing.T, v executable) { | ||
log.SetOutput(ioutil.Discard) | ||
defer log.SetOutput(os.Stdout) | ||
|
||
specDoc := filepath.Join(fixtureBase, "expansion", "invalid-refs.json") | ||
result := v.Execute([]string{specDoc}) | ||
assert.Error(t, result) | ||
} | ||
|
||
func testRequireParam(t *testing.T, v executable) { | ||
log.SetOutput(ioutil.Discard) | ||
defer log.SetOutput(os.Stdout) | ||
|
||
result := v.Execute([]string{}) | ||
assert.Error(t, result) | ||
|
||
result = v.Execute([]string{"nowhere.json"}) | ||
assert.Error(t, result) | ||
} | ||
|
||
func getOutput(t *testing.T, specDoc, prefix, filename string) (string, string) { | ||
outDir, err := ioutil.TempDir(filepath.Dir(specDoc), "flatten") | ||
if !assert.NoError(t, err) { | ||
t.FailNow() | ||
} | ||
return outDir, filepath.Join(outDir, filename) | ||
} | ||
|
||
func testProduceOutput(t *testing.T, v executable, specDoc, output string) { | ||
log.SetOutput(ioutil.Discard) | ||
defer log.SetOutput(os.Stdout) | ||
|
||
result := v.Execute([]string{specDoc}) | ||
assert.NoError(t, result) | ||
_, exists := os.Stat(output) | ||
assert.True(t, !os.IsNotExist(exists)) | ||
} | ||
|
||
// Commands requires at least one arg | ||
func TestCmd_Flatten(t *testing.T) { | ||
v := &FlattenSpec{} | ||
testRequireParam(t, v) | ||
} | ||
|
||
func TestCmd_Flatten_Default(t *testing.T) { | ||
specDoc := filepath.Join(fixtureBase, "bugs", "1536", "fixture-1536.yaml") | ||
outDir, output := getOutput(t, specDoc, "flatten", "fixture-1536-flat-minimal.json") | ||
defer os.RemoveAll(outDir) | ||
v := &FlattenSpec{ | ||
Format: "json", | ||
Compact: true, | ||
Output: flags.Filename(output), | ||
} | ||
testProduceOutput(t, v, specDoc, output) | ||
} | ||
|
||
func TestCmd_Flatten_Error(t *testing.T) { | ||
v := &FlattenSpec{} | ||
testValidRefs(t, v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package generate_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/go-swagger/go-swagger/cmd/swagger/commands/generate" | ||
flags "github.com/jessevdk/go-flags" | ||
) | ||
|
||
func TestGenerateClient(t *testing.T) { | ||
specs := []string{ | ||
"tasklist.basic.yml", | ||
"todolist.simplequery.yml", | ||
} | ||
log.SetOutput(ioutil.Discard) | ||
defer log.SetOutput(os.Stdout) | ||
|
||
base := filepath.FromSlash("../../../../") | ||
for i, spec := range specs { | ||
_ = t.Run(spec, func(t *testing.T) { | ||
path := filepath.Join(base, "fixtures/codegen", spec) | ||
generated, err := ioutil.TempDir(filepath.Dir(path), "generated") | ||
if err != nil { | ||
t.Fatalf("TempDir()=%s", generated) | ||
} | ||
defer func() { | ||
_ = os.RemoveAll(generated) | ||
}() | ||
m := &generate.Client{} | ||
_, _ = flags.Parse(m) | ||
if i == 0 { | ||
m.CopyrightFile = flags.Filename(filepath.Join(base, "LICENSE")) | ||
} | ||
m.Spec = flags.Filename(path) | ||
m.Target = flags.Filename(generated) | ||
|
||
if err := m.Execute([]string{}); err != nil { | ||
t.Error(err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGenerateClient_Check(t *testing.T) { | ||
log.SetOutput(ioutil.Discard) | ||
defer log.SetOutput(os.Stdout) | ||
|
||
m := &generate.Client{} | ||
_, _ = flags.Parse(m) | ||
m.CopyrightFile = "nullePart" | ||
err := m.Execute([]string{}) | ||
assert.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.