Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pytimer committed Mar 30, 2022
1 parent 336084b commit 56a4e31
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
35 changes: 35 additions & 0 deletions golist_test.go
@@ -0,0 +1,35 @@
package swag

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestListPackages(t *testing.T) {
searchDir := "testdata/golist"

cases := []struct {
name string
args []string
}{
{
name: "errorArgs",
args: []string{"-abc"},
},
{
name: "normal",
args: []string{"-deps"},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
_, err := listPackages(context.TODO(), searchDir, nil, c.args...)
assert.NoError(t, err)
})

}

}
30 changes: 28 additions & 2 deletions parser_test.go
Expand Up @@ -2133,8 +2133,34 @@ func TestParseGoList(t *testing.T) {
mainAPIFile := "main.go"
p := New(ParseUsingGoList(true))
p.ParseDependency = true
err := p.ParseAPI(searchDir, mainAPIFile, defaultParseDepth)
assert.NoError(t, err)

go111moduleEnv := os.Getenv("GO111MODULE")

cases := []struct {
name string
gomodule bool
}{
{
name: "enableGOMODULE",
gomodule: true,
},
{
name: "disableGOMODULE",
gomodule: false,
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if !c.gomodule {
os.Setenv("GO111MODULE", "off")
}
err := p.ParseAPI(searchDir, mainAPIFile, defaultParseDepth)
os.Setenv("GO111MODULE", go111moduleEnv)
assert.NoError(t, err)
})

}
}

func TestParser_ParseStructArrayObject(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion testdata/golist/main.go
Expand Up @@ -19,12 +19,14 @@ import (
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @securityDefinitions.apikey ApiKeyAuth

// @host petstore.swagger.io
// @BasePath /v2
func main() {
goapi.PrintInt(10, 5)
http.HandleFunc("/testapi/get-string-by-int/", api.GetStringByInt)
http.HandleFunc("//testapi/get-struct-array-by-string/", api.GetStructArrayByString)
http.HandleFunc("/testapi/get-struct-array-by-string/", api.GetStructArrayByString)
http.HandleFunc("/testapi/upload", api.Upload)
http.ListenAndServe(":8080", nil)
}

0 comments on commit 56a4e31

Please sign in to comment.