Skip to content

Commit

Permalink
chore: Bump major version, add evaluation context codegen to CI (#142)
Browse files Browse the repository at this point in the history
* chore: Bump major version, add evaluation context codegen to CI
  • Loading branch information
khvn26 authored Oct 23, 2024
1 parent ec6639a commit c454725
Show file tree
Hide file tree
Showing 28 changed files with 97 additions and 108 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
with:
submodules: recursive

- name: Build evaluation context struct
run: make generate-evaluation-context

- name: Get dependencies
run: |
go get -v -t -d ./...
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/lint.yml

This file was deleted.

17 changes: 4 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0

hooks:
- id: go-fmt
- id: go-vet
- id: go-imports
- id: golangci-lint
- id: go-build
- id: go-critic
- id: go-mod-tidy


- repo: https://github.com/golangci/golangci-lint
rev: v1.61.0
hooks:
- id: golangci-lint
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ EVALUATION_CONTEXT_SCHEMA_URL ?= https://raw.githubusercontent.com/Flagsmith/fla

.PHONY: generate-evaluation-context
generate-evaluation-context:
npx quicktype ${EVALUATION_CONTEXT_SCHEMA_URL} --src-lang schema --lang go --package flagsmith --omit-empty --just-types-and-package > evaluationcontext.go
npx quicktype ${EVALUATION_CONTEXT_SCHEMA_URL} \
--src-lang schema \
--lang go \
--package flagsmith \
--omit-empty \
--just-types-and-package \
> evaluationcontext.go
14 changes: 7 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"sync/atomic"
"time"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
"github.com/go-resty/resty/v2"

enginetraits "github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
enginetraits "github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
)

type contextKey string
Expand Down Expand Up @@ -117,7 +117,7 @@ func (c *Client) GetFlags(ctx context.Context, ec *EvaluationContext) (f Flags,
if ec != nil {
ctx = WithEvaluationContext(ctx, *ec)
if ec.Identity != nil {
return c.GetIdentityFlags(ctx, ec.Identity.Identifier, mapIdentityEvaluationContextToTraits(*ec.Identity))
return c.GetIdentityFlags(ctx, *ec.Identity.Identifier, mapIdentityEvaluationContextToTraits(*ec.Identity))
}
}
return c.GetEnvironmentFlags(ctx)
Expand Down Expand Up @@ -263,7 +263,7 @@ func (c *Client) GetIdentityFlagsFromAPI(ctx context.Context, identifier string,
idCtx := ec.Identity
if idCtx != nil {
// `Identifier` and `Traits` had been set by `GetFlags` earlier.
body.Transient = &idCtx.Transient
body.Transient = idCtx.Transient
}
}
resp, err := req.
Expand Down
19 changes: 12 additions & 7 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"testing"
"time"

flagsmith "github.com/Flagsmith/flagsmith-go-client/v3"
"github.com/Flagsmith/flagsmith-go-client/v3/fixtures"
flagsmith "github.com/Flagsmith/flagsmith-go-client/v4"
"github.com/Flagsmith/flagsmith-go-client/v4/fixtures"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -204,6 +204,8 @@ func TestGetFlags(t *testing.T) {

func TestGetFlagsTransientIdentity(t *testing.T) {
// Given
identifier := "transient"
transient := true
ctx := context.Background()
expectedRequestBody := `{"identifier":"transient","transient":true}`
server := getTestHttpServer(t, "/api/v1/identities/", fixtures.EnvironmentAPIKey, &expectedRequestBody, fixtures.IdentityResponseJson)
Expand All @@ -212,7 +214,7 @@ func TestGetFlagsTransientIdentity(t *testing.T) {
// When
client := flagsmith.NewClient(fixtures.EnvironmentAPIKey, flagsmith.WithBaseURL(server.URL+"/api/v1/"))

flags, err := client.GetFlags(ctx, &flagsmith.EvaluationContext{Identity: &flagsmith.IdentityEvaluationContext{Identifier: "transient", Transient: true}})
flags, err := client.GetFlags(ctx, &flagsmith.EvaluationContext{Identity: &flagsmith.IdentityEvaluationContext{Identifier: &identifier, Transient: &transient}})

// Then
assert.NoError(t, err)
Expand All @@ -228,11 +230,13 @@ func TestGetFlagsTransientIdentity(t *testing.T) {

func TestGetFlagsTransientTraits(t *testing.T) {
// Given
identifier := "test_identity"
transient := true
ctx := context.Background()
expectedRequestBody := `{"identifier":"test_identity","traits":` +
`[{"trait_key":"NullTrait","trait_value":null},` +
`{"trait_key":"StringTrait","trait_value":"value"},` +
`{"trait_key":"TransientTrait","trait_value":"value","transient":true}],"transient":false}`
`{"trait_key":"TransientTrait","trait_value":"value","transient":true}]}`
server := getTestHttpServer(t, "/api/v1/identities/", fixtures.EnvironmentAPIKey, &expectedRequestBody, fixtures.IdentityResponseJson)
defer server.Close()

Expand All @@ -243,13 +247,13 @@ func TestGetFlagsTransientTraits(t *testing.T) {
ctx,
&flagsmith.EvaluationContext{
Identity: &flagsmith.IdentityEvaluationContext{
Identifier: "test_identity",
Identifier: &identifier,
Traits: map[string]*flagsmith.TraitEvaluationContext{
"NullTrait": nil,
"StringTrait": {Value: "value"},
"TransientTrait": {
Value: "value",
Transient: true,
Transient: &transient,
},
},
},
Expand Down Expand Up @@ -289,6 +293,7 @@ func TestGetFlagsEnvironmentEvaluationContextFlags(t *testing.T) {

func TestGetFlagsEnvironmentEvaluationContextIdentity(t *testing.T) {
// Given
identifier := "test_identity"
ctx := context.Background()
expectedEnvKey := "different"
server := getTestHttpServer(t, "/api/v1/identities/", expectedEnvKey, nil, fixtures.IdentityResponseJson)
Expand All @@ -301,7 +306,7 @@ func TestGetFlagsEnvironmentEvaluationContextIdentity(t *testing.T) {
ctx,
&flagsmith.EvaluationContext{
Environment: &flagsmith.EnvironmentEvaluationContext{APIKey: expectedEnvKey},
Identity: &flagsmith.IdentityEvaluationContext{Identifier: "test_identity"},
Identity: &flagsmith.IdentityEvaluationContext{Identifier: &identifier},
})

// Then
Expand Down
6 changes: 3 additions & 3 deletions evaluationcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type FeatureEvaluationContext struct {
}

type IdentityEvaluationContext struct {
Identifier string `json:"identifier,omitempty"`
Identifier *string `json:"identifier,omitempty"`
Traits map[string]*TraitEvaluationContext `json:"traits,omitempty"`
Transient bool `json:"transient,omitempty"`
Transient *bool `json:"transient,omitempty"`
}

type TraitEvaluationContext struct {
Transient bool `json:"transient,omitempty"`
Transient *bool `json:"transient,omitempty"`
Value interface{} `json:"value"`
}
7 changes: 4 additions & 3 deletions evaluationcontext_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func getTraitEvaluationContext(v interface{}) TraitEvaluationContext {
}

func NewTraitEvaluationContext(value interface{}, transient bool) TraitEvaluationContext {
return TraitEvaluationContext{Value: value, Transient: transient}
return TraitEvaluationContext{Value: value, Transient: &transient}
}

func NewEvaluationContext(identifier string, traits map[string]interface{}) EvaluationContext {
Expand All @@ -20,14 +20,15 @@ func NewEvaluationContext(identifier string, traits map[string]interface{}) Eval
traitsCtx[tKey] = &tCtx
}
ec.Identity = &IdentityEvaluationContext{
Identifier: identifier,
Identifier: &identifier,
Traits: traitsCtx,
}
return ec
}

func NewTransientEvaluationContext(identifier string, traits map[string]interface{}) EvaluationContext {
ec := NewEvaluationContext(identifier, traits)
ec.Identity.Transient = true
var transient = true
ec.Identity.Transient = &transient
return ec
}
10 changes: 5 additions & 5 deletions flagengine/engine.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package flagengine

import (
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
)

// GetEnvironmentFeatureStates returns a list of feature states for a given environment.
Expand Down
10 changes: 5 additions & 5 deletions flagengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package flagengine_test
import (
"testing"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils/fixtures"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils/fixtures"
"github.com/stretchr/testify/assert"
)

Expand Down
6 changes: 3 additions & 3 deletions flagengine/environments/models.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package environments

import (
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/projects"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/projects"
)

type EnvironmentModel struct {
Expand Down
2 changes: 1 addition & 1 deletion flagengine/features/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sort"
"strconv"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

type FeatureModel struct {
Expand Down
2 changes: 1 addition & 1 deletion flagengine/features/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package features_test
import (
"testing"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/stretchr/testify/assert"
)

Expand Down
10 changes: 5 additions & 5 deletions flagengine/flagengine_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
)

const TestData = "./engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json"
Expand Down
6 changes: 3 additions & 3 deletions flagengine/identities/models.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package identities

import (
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

type IdentityModel struct {
Expand Down
4 changes: 2 additions & 2 deletions flagengine/projects/models.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package projects

import (
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/organisations"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/organisations"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
)

type ProjectModel struct {
Expand Down
6 changes: 3 additions & 3 deletions flagengine/segments/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"strconv"
"strings"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
"github.com/blang/semver/v4"
"golang.org/x/exp/slices"
)
Expand Down
10 changes: 5 additions & 5 deletions flagengine/segments/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

"github.com/stretchr/testify/assert"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils/fixtures"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils/fixtures"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions flagengine/segments/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strconv"
"strings"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

type SegmentConditionModel struct {
Expand Down
16 changes: 8 additions & 8 deletions flagengine/utils/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package fixtures
import (
"time"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/organisations"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/projects"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/organisations"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/projects"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

const (
Expand Down
Loading

0 comments on commit c454725

Please sign in to comment.