-
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.
* Add coverage target in makefile Signed-off-by: Mahendra Paipuri <[email protected]>
- Loading branch information
1 parent
0c45899
commit 313eeb4
Showing
8 changed files
with
138 additions
and
50 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
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,45 @@ | ||
package structset | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
// testStruct is a test struct that will be used in tests | ||
type testStruct struct { | ||
ID int `json:"id" sql:"id"` | ||
Field1 string `json:"field1" sql:"f1"` | ||
Field2 bool `json:"field2" sql:"f2"` | ||
Field3 interface{} `json:"field3" sql:"f3"` | ||
Field4 []string `json:"field4" sql:"f4"` | ||
} | ||
|
||
func TestGetStructFieldNames(t *testing.T) { | ||
fields := GetStructFieldNames(testStruct{}) | ||
expectedFields := []string{"ID", "Field1", "Field2", "Field3", "Field4"} | ||
if !reflect.DeepEqual(fields, expectedFields) { | ||
t.Errorf("expected %v, got %v", expectedFields, fields) | ||
} | ||
} | ||
|
||
func TestGetStructFieldValues(t *testing.T) { | ||
tags := GetStructFieldTagValues(testStruct{}, "json") | ||
expectedTags := []string{"field1", "field2", "field3", "field4"} | ||
if !reflect.DeepEqual(tags, expectedTags) { | ||
t.Errorf("expected %v, got %v", expectedTags, tags) | ||
} | ||
} | ||
|
||
func TestGetStructFieldTagMap(t *testing.T) { | ||
tagMap := GetStructFieldTagMap(testStruct{}, "json", "sql") | ||
expectedTagMap := map[string]string{ | ||
"id": "id", | ||
"field1": "f1", | ||
"field2": "f2", | ||
"field3": "f3", | ||
"field4": "f4", | ||
} | ||
if !reflect.DeepEqual(tagMap, expectedTagMap) { | ||
t.Errorf("expected %v, got %v", expectedTagMap, tagMap) | ||
} | ||
} |
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,13 @@ | ||
package http | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestApiError(t *testing.T) { | ||
e := apiError{typ: errorBadData, err: fmt.Errorf("bad data")} | ||
if e.Error() != "bad_data: bad data" { | ||
t.Errorf("expected error bad_data: bad data, got %s", e.Error()) | ||
} | ||
} |