micro: add simple test
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
		| @@ -392,8 +392,12 @@ type nameIface interface { | |||||||
| 	Name() string | 	Name() string | ||||||
| } | } | ||||||
|  |  | ||||||
| func getNameIndex(n string, ifaces ...interface{}) int { | func getNameIndex(n string, ifaces interface{}) int { | ||||||
| 	for idx, iface := range ifaces { | 	values, ok := ifaces.([]interface{}) | ||||||
|  | 	if !ok { | ||||||
|  | 		return 0 | ||||||
|  | 	} | ||||||
|  | 	for idx, iface := range values { | ||||||
| 		if ifc, ok := iface.(nameIface); ok && ifc.Name() == n { | 		if ifc, ok := iface.(nameIface); ok && ifc.Name() == n { | ||||||
| 			return idx | 			return idx | ||||||
| 		} | 		} | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								service_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								service_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | package micro | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"testing" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | type testItem struct { | ||||||
|  | 	name string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (ti *testItem) Name() string { | ||||||
|  | 	return ti.name | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func TestGetNameIndex(t *testing.T) { | ||||||
|  | 	item1 := &testItem{name: "first"} | ||||||
|  | 	item2 := &testItem{name: "second"} | ||||||
|  | 	items := []interface{}{item1, item2} | ||||||
|  | 	if idx := getNameIndex("second", items); idx != 1 { | ||||||
|  | 		t.Fatalf("getNameIndex func error, item not found") | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user