@@ -2,6 +2,7 @@ package evaluation
2
2
3
3
import (
4
4
"reflect"
5
+ "strconv"
5
6
"testing"
6
7
7
8
"github.com/harness/ff-golang-server-sdk/rest"
@@ -54,9 +55,10 @@ func Test_getAttrValue(t *testing.T) {
54
55
attr string
55
56
}
56
57
tests := []struct {
57
- name string
58
- args args
59
- want reflect.Value
58
+ name string
59
+ args args
60
+ want reflect.Value
61
+ wantStr string
60
62
}{
61
63
{
62
64
name : "check identifier" ,
@@ -66,7 +68,8 @@ func Test_getAttrValue(t *testing.T) {
66
68
},
67
69
attr : identifier ,
68
70
},
69
- want : reflect .ValueOf (harness ),
71
+ want : reflect .ValueOf (harness ),
72
+ wantStr : "harness" ,
70
73
},
71
74
{
72
75
name : "check name" ,
@@ -76,7 +79,8 @@ func Test_getAttrValue(t *testing.T) {
76
79
},
77
80
attr : "name" ,
78
81
},
79
- want : reflect .ValueOf (harness ),
82
+ want : reflect .ValueOf (harness ),
83
+ wantStr : "harness" ,
80
84
},
81
85
{
82
86
name : "check attributes" ,
@@ -89,14 +93,73 @@ func Test_getAttrValue(t *testing.T) {
89
93
},
90
94
attr : "email" ,
91
95
},
92
- want : reflect .ValueOf (email ),
96
+ want : reflect .ValueOf (email ),
97
+ wantStr : email ,
98
+ },
99
+ {
100
+ name : "check integer attributes" ,
101
+ args : args {
102
+ target : & Target {
103
+ Identifier : identifier ,
104
+ Attributes : & map [string ]interface {}{
105
+ "age" : 123 ,
106
+ },
107
+ },
108
+ attr : "age" ,
109
+ },
110
+ want : reflect .ValueOf (123 ),
111
+ wantStr : "123" ,
112
+ },
113
+ {
114
+ name : "check int64 attributes" ,
115
+ args : args {
116
+ target : & Target {
117
+ Identifier : identifier ,
118
+ Attributes : & map [string ]interface {}{
119
+ "age" : int64 (123 ),
120
+ },
121
+ },
122
+ attr : "age" ,
123
+ },
124
+ want : reflect .ValueOf (int64 (123 )),
125
+ wantStr : "123" ,
126
+ },
127
+ {
128
+ name : "check boolean attributes" ,
129
+ args : args {
130
+ target : & Target {
131
+ Identifier : identifier ,
132
+ Attributes : & map [string ]interface {}{
133
+ "active" : true ,
134
+ },
135
+ },
136
+ attr : "active" ,
137
+ },
138
+ want : reflect .ValueOf (true ),
139
+ wantStr : "true" ,
93
140
},
94
141
}
95
142
for _ , tt := range tests {
96
143
t .Run (tt .name , func (t * testing.T ) {
97
- if got := getAttrValue (tt .args .target , tt .args .attr ); ! reflect .DeepEqual (got .Interface (), tt .want .Interface ()) {
144
+ got := getAttrValue (tt .args .target , tt .args .attr )
145
+ if ! reflect .DeepEqual (got .Interface (), tt .want .Interface ()) {
98
146
t .Errorf ("getAttrValue() = %v, want %v" , got , tt .want )
99
147
}
148
+
149
+ expObjString := ""
150
+ //nolint
151
+ switch got .Kind () {
152
+ case reflect .Int , reflect .Int64 :
153
+ expObjString = strconv .FormatInt (got .Int (), 10 )
154
+ case reflect .Bool :
155
+ expObjString = strconv .FormatBool (got .Bool ())
156
+ case reflect .String :
157
+ expObjString = got .String ()
158
+ }
159
+
160
+ if expObjString != tt .wantStr {
161
+ t .Errorf ("getAttrValue() expObjString= %v, want %v" , got .String (), tt .wantStr )
162
+ }
100
163
})
101
164
}
102
165
}
0 commit comments