Skip to content

Commit a1a3397

Browse files
FFM-3703 - Go FF SDK Broken by Kin API Changes (#90)
* Update Kin and OpenAPI versions, add yaml config for openAPI version change, update tests, code where needed to respect new version gen code
1 parent 3d83f1a commit a1a3397

19 files changed

+426
-205
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ endif
88
all: tidy generate build check test
99

1010
generate:
11-
oapi-codegen -generate client,spec -package=rest ./resources/client-v1.yaml > rest/services.gen.go
12-
oapi-codegen -generate types -package=rest ./resources/client-v1.yaml > rest/types.gen.go
13-
oapi-codegen -generate client -package=metricsclient ./resources/metrics-v1.yaml > metricsclient/services.gen.go
14-
oapi-codegen -generate types -package=metricsclient ./resources/metrics-v1.yaml > metricsclient/types.gen.go
11+
oapi-codegen --config ./resources/config/rest-client-config.yaml ./resources/client-v1.yaml > rest/services.gen.go
12+
oapi-codegen --config ./resources/config/rest-types-config.yaml ./resources/client-v1.yaml > rest/types.gen.go
13+
oapi-codegen --config ./resources/config/metrics-client-config.yaml ./resources/metrics-v1.yaml > metricsclient/services.gen.go
14+
oapi-codegen --config ./resources/config/metrics-types-config.yaml ./resources/metrics-v1.yaml > metricsclient/types.gen.go
1515

1616
tidy:
1717
go mod tidy
@@ -95,7 +95,7 @@ $(GOPATH)/bin/gosec:
9595

9696
$(GOPATH)/bin/oapi-codegen:
9797
@echo "🔘 Installing oapicodegen ... (`date '+%H:%M:%S'`)"
98-
@go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.6.0
98+
@go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.11.0
9999

100100
PHONY+= tools
101101
tools: $(GOPATH)/bin/golangci-lint $(GOPATH)/bin/golint $(GOPATH)/bin/gosec $(GOPATH)/bin/goimports $(GOPATH)/bin/oapi-codegen

analyticsservice/analytics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (as *AnalyticsService) sendDataAndResetCache(ctx context.Context) {
228228
md := metricsclient.MetricsData{
229229
Timestamp: time.Now().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond)),
230230
Count: analytic.count,
231-
MetricsType: ffMetricType,
231+
MetricsType: metricsclient.MetricsDataMetricsType(ffMetricType),
232232
Attributes: metricAttributes,
233233
}
234234
metricData = append(metricData, md)

evaluation/evaluator.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (e Evaluator) evaluateVariationMap(variationsMap []rest.VariationMap, targe
203203

204204
func (e Evaluator) evaluateFlag(fc rest.FeatureConfig, target *Target) (rest.Variation, error) {
205205
var variation = fc.OffVariation
206-
if fc.State == rest.FeatureState_on {
206+
if fc.State == rest.FeatureStateOn {
207207
variation = ""
208208
if fc.VariationToTargetMap != nil {
209209
variation = e.evaluateVariationMap(*fc.VariationToTargetMap, target)
@@ -321,8 +321,7 @@ func (e Evaluator) evaluate(identifier string, target *Target, kind string) (res
321321
if err != nil {
322322
return rest.Variation{}, err
323323
}
324-
325-
if flag.Kind != kind {
324+
if string(flag.Kind) != kind {
326325
return rest.Variation{}, fmt.Errorf("%w, expected: %s, got: %s", ErrFlagKindMismatch, kind, flag.Kind)
327326
}
328327

evaluation/evaluator_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var (
104104
map[string]rest.FeatureConfig{
105105
simple: {
106106
Feature: simple,
107-
State: rest.FeatureState_on,
107+
State: rest.FeatureStateOn,
108108
DefaultServe: rest.Serve{
109109
Variation: &identifierTrue,
110110
},
@@ -113,7 +113,7 @@ var (
113113
},
114114
theme: {
115115
Feature: theme,
116-
State: rest.FeatureState_on,
116+
State: rest.FeatureStateOn,
117117
DefaultServe: rest.Serve{
118118
Variation: &lighttheme,
119119
},
@@ -122,7 +122,7 @@ var (
122122
},
123123
size: {
124124
Feature: size,
125-
State: rest.FeatureState_on,
125+
State: rest.FeatureStateOn,
126126
DefaultServe: rest.Serve{
127127
Variation: &mediumSize,
128128
},
@@ -131,7 +131,7 @@ var (
131131
},
132132
weight: {
133133
Feature: weight,
134-
State: rest.FeatureState_on,
134+
State: rest.FeatureStateOn,
135135
DefaultServe: rest.Serve{
136136
Variation: &heavyWeight,
137137
},
@@ -140,7 +140,7 @@ var (
140140
},
141141
org: {
142142
Feature: org,
143-
State: rest.FeatureState_on,
143+
State: rest.FeatureStateOn,
144144
DefaultServe: rest.Serve{
145145
Variation: &json2,
146146
},
@@ -149,7 +149,7 @@ var (
149149
},
150150
invalidInt: {
151151
Feature: invalidInt,
152-
State: rest.FeatureState_on,
152+
State: rest.FeatureStateOn,
153153
DefaultServe: rest.Serve{
154154
Variation: &invalidIntValue,
155155
},
@@ -163,7 +163,7 @@ var (
163163
},
164164
invalidNumber: {
165165
Feature: invalidNumber,
166-
State: rest.FeatureState_on,
166+
State: rest.FeatureStateOn,
167167
DefaultServe: rest.Serve{
168168
Variation: &invalidNumberValue,
169169
},
@@ -177,7 +177,7 @@ var (
177177
},
178178
invalidJSON: {
179179
Feature: invalidJSON,
180-
State: rest.FeatureState_on,
180+
State: rest.FeatureStateOn,
181181
DefaultServe: rest.Serve{
182182
Variation: &invalidNumberValue,
183183
},
@@ -191,7 +191,7 @@ var (
191191
},
192192
simpleWithPrereq: {
193193
Feature: simpleWithPrereq,
194-
State: rest.FeatureState_on,
194+
State: rest.FeatureStateOn,
195195
DefaultServe: rest.Serve{
196196
Variation: &identifierTrue,
197197
},
@@ -206,7 +206,7 @@ var (
206206
},
207207
prereqNotFound: {
208208
Feature: prereqNotFound,
209-
State: rest.FeatureState_on,
209+
State: rest.FeatureStateOn,
210210
DefaultServe: rest.Serve{
211211
Variation: &identifierTrue,
212212
},
@@ -222,7 +222,7 @@ var (
222222
prereqVarNotFound: {
223223
Feature: prereqVarNotFound,
224224
OffVariation: offVariation,
225-
State: rest.FeatureState_on,
225+
State: rest.FeatureStateOn,
226226
DefaultServe: rest.Serve{
227227
Variation: &identifierTrue,
228228
},
@@ -237,7 +237,7 @@ var (
237237
},
238238
notValidFlag: {
239239
Feature: notValidFlag,
240-
State: rest.FeatureState_on,
240+
State: rest.FeatureStateOn,
241241
DefaultServe: rest.Serve{
242242
Variation: &empty,
243243
},
@@ -952,7 +952,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
952952
args: args{
953953
fc: rest.FeatureConfig{
954954
OffVariation: offVariation,
955-
State: rest.FeatureState_off,
955+
State: rest.FeatureStateOff,
956956
Variations: boolVariations,
957957
},
958958
},
@@ -964,7 +964,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
964964
args: args{
965965
fc: rest.FeatureConfig{
966966
OffVariation: offVariation,
967-
State: rest.FeatureState_off,
967+
State: rest.FeatureStateOff,
968968
Variations: boolVariations,
969969
},
970970
target: &Target{
@@ -978,7 +978,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
978978
name: "evaluate flag should return default serve variation",
979979
args: args{
980980
fc: rest.FeatureConfig{
981-
State: rest.FeatureState_on,
981+
State: rest.FeatureStateOn,
982982
Variations: boolVariations,
983983
DefaultServe: rest.Serve{
984984
Variation: &boolVariations[0].Value,
@@ -995,7 +995,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
995995
name: "evaluate flag should return default serve distribution",
996996
args: args{
997997
fc: rest.FeatureConfig{
998-
State: rest.FeatureState_on,
998+
State: rest.FeatureStateOn,
999999
Variations: boolVariations,
10001000
DefaultServe: rest.Serve{
10011001
Distribution: &rest.Distribution{
@@ -1023,7 +1023,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
10231023
name: "evaluate flag should return rule serve",
10241024
args: args{
10251025
fc: rest.FeatureConfig{
1026-
State: rest.FeatureState_on,
1026+
State: rest.FeatureStateOn,
10271027
Variations: boolVariations,
10281028
Rules: &[]rest.ServingRule{
10291029
{
@@ -1051,7 +1051,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
10511051
name: "evaluate flag using variationMap and target should return 'true'",
10521052
args: args{
10531053
fc: rest.FeatureConfig{
1054-
State: rest.FeatureState_on,
1054+
State: rest.FeatureStateOn,
10551055
Variations: boolVariations,
10561056
VariationToTargetMap: &[]rest.VariationMap{
10571057
{
@@ -1075,7 +1075,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
10751075
name: "evaluate flag variation returns an error",
10761076
args: args{
10771077
fc: rest.FeatureConfig{
1078-
State: rest.FeatureState_on,
1078+
State: rest.FeatureStateOn,
10791079
},
10801080
target: &Target{
10811081
Identifier: targetIdentifier,
@@ -1240,7 +1240,7 @@ func TestEvaluator_checkPreRequisite(t *testing.T) {
12401240
},
12411241
args: args{
12421242
parent: &rest.FeatureConfig{
1243-
State: rest.FeatureState_on,
1243+
State: rest.FeatureStateOn,
12441244
Prerequisites: &[]rest.Prerequisite{
12451245
{
12461246
Feature: simple,
@@ -1258,7 +1258,7 @@ func TestEvaluator_checkPreRequisite(t *testing.T) {
12581258
},
12591259
args: args{
12601260
parent: &rest.FeatureConfig{
1261-
State: rest.FeatureState_on,
1261+
State: rest.FeatureStateOn,
12621262
Prerequisites: &[]rest.Prerequisite{
12631263
{
12641264
Feature: "prereq not found",

go.mod

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ module github.com/harness/ff-golang-server-sdk
33
go 1.16
44

55
require (
6-
github.com/deepmap/oapi-codegen v1.6.0
7-
github.com/fatih/structtag v1.2.0 // indirect
8-
github.com/getkin/kin-openapi v0.53.0
9-
github.com/golang-jwt/jwt v3.2.1+incompatible
10-
github.com/google/uuid v1.2.0
6+
github.com/deepmap/oapi-codegen v1.11.0
7+
github.com/getkin/kin-openapi v0.94.0
8+
github.com/golang-jwt/jwt v3.2.2+incompatible
9+
github.com/google/uuid v1.3.0
1110
github.com/hashicorp/go-retryablehttp v0.6.8
1211
github.com/hashicorp/golang-lru v0.5.4
1312
github.com/jarcoal/httpmock v1.0.8
14-
github.com/json-iterator/go v1.1.10
13+
github.com/json-iterator/go v1.1.12
1514
github.com/mitchellh/go-homedir v1.1.0
1615
github.com/mitchellh/mapstructure v1.3.3
1716
github.com/r3labs/sse v0.0.0-20201126193848-34e640891548
1817
github.com/spaolacci/murmur3 v1.1.0
19-
github.com/stretchr/testify v1.5.1
18+
github.com/stretchr/testify v1.7.1
2019
go.uber.org/multierr v1.6.0 // indirect
2120
go.uber.org/zap v1.16.0
22-
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f // indirect
23-
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
21+
gopkg.in/cenkalti/backoff.v1 v1.1.0
2422
)

0 commit comments

Comments
 (0)