-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to extract api struct name
part of #98
- Loading branch information
Ivan Vlasic
committed
Dec 2, 2021
1 parent
0ec49f4
commit 6d15cc6
Showing
9 changed files
with
142 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestExtractApiStructNamePtr(t *testing.T) { | ||
stc, err := extractApiStructName("ping", "testdata/generate/ping_ptr") | ||
require.NoError(t, err) | ||
assert.Equal(t, "Ping", stc) | ||
} | ||
|
||
func TestExtractApiStructNameStruct(t *testing.T) { | ||
stc, err := extractApiStructName("ping", "testdata/generate/ping_struct") | ||
require.NoError(t, err) | ||
assert.Equal(t, "Ping", stc) | ||
} | ||
|
||
func TestExtractApiStructNameNoNew(t *testing.T) { | ||
_, err := extractApiStructName("ping", "testdata/generate/no_new") | ||
fmt.Println(err) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestExtractApiStructNameNewWithParameters(t *testing.T) { | ||
_, err := extractApiStructName("ping", "testdata/generate/parameters") | ||
fmt.Println(err) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestExtractApiStructNameTooManyValues(t *testing.T) { | ||
_, err := extractApiStructName("ping", "testdata/generate/return_values") | ||
fmt.Println(err) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestExtractApiStructNameWrongValue(t *testing.T) { | ||
_, err := extractApiStructName("ping", "testdata/generate/return_value") | ||
fmt.Println(err) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestExtractApiStructNameNewWrongType(t *testing.T) { | ||
_, err := extractApiStructName("ping", "testdata/generate/new_wrong_type") | ||
fmt.Println(err) | ||
require.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package ping | ||
|
||
const New = "this should be a function" |
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,3 @@ | ||
package ping | ||
|
||
type Ping struct{} |
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,7 @@ | ||
package ping | ||
|
||
type Ping struct{} | ||
|
||
func New(par string) *Ping { | ||
return Ping{} | ||
} |
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,7 @@ | ||
package ping | ||
|
||
type Ping struct{} | ||
|
||
func New() *Ping { | ||
return &Ping{} | ||
} |
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,7 @@ | ||
package ping | ||
|
||
type Ping struct{} | ||
|
||
func New() Ping { | ||
return Ping{} | ||
} |
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,7 @@ | ||
package ping | ||
|
||
type Ping struct{} | ||
|
||
func New() int { | ||
return -1 | ||
} |
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,7 @@ | ||
package ping | ||
|
||
type Ping struct{} | ||
|
||
func New() (*Ping, error) { | ||
return Ping{} | ||
} |