Skip to content

Commit

Permalink
Merge branch 'master' into yasir/refact-polling-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
msohailhussain committed Jan 15, 2020
2 parents 91fa12a + b75e05a commit 67eec57
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 22 deletions.
36 changes: 18 additions & 18 deletions pkg/config/optimizely_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,40 @@ import "github.com/optimizely/go-sdk/pkg/entities"

// OptimizelyConfig is a snapshot of the experiments and features in the project config
type OptimizelyConfig struct {
Revision string
ExperimentsMap map[string]OptimizelyExperiment
FeaturesMap map[string]OptimizelyFeature
Revision string `json:"revision"`
ExperimentsMap map[string]OptimizelyExperiment `json:"experimentsMap"`
FeaturesMap map[string]OptimizelyFeature `json:"featuresMap"`
}

// OptimizelyExperiment has experiment info
type OptimizelyExperiment struct {
ID string
Key string
VariationsMap map[string]OptimizelyVariation
ID string `json:"id"`
Key string `json:"key"`
VariationsMap map[string]OptimizelyVariation `json:"variationsMap"`
}

// OptimizelyFeature has feature info
type OptimizelyFeature struct {
ID string
Key string
ExperimentsMap map[string]OptimizelyExperiment
VariablesMap map[string]OptimizelyVariable
ID string `json:"id"`
Key string `json:"key"`
ExperimentsMap map[string]OptimizelyExperiment `json:"experimentsMap"`
VariablesMap map[string]OptimizelyVariable `json:"variablesMap"`
}

// OptimizelyVariation has variation info
type OptimizelyVariation struct {
ID string
Key string
FeatureEnabled bool
VariablesMap map[string]OptimizelyVariable
ID string `json:"id"`
Key string `json:"key"`
FeatureEnabled bool `json:"featureEnabled"`
VariablesMap map[string]OptimizelyVariable `json:"variablesMap"`
}

// OptimizelyVariable has variable info
type OptimizelyVariable struct {
ID string
Key string
Type string
Value string
ID string `json:"id"`
Key string `json:"key"`
Type string `json:"type"`
Value string `json:"value"`
}

func getVariableByIDMap(features []entities.Feature) (variableByIDMap map[string]entities.Variable) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/event/events.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2019, Optimizely, Inc. and contributors *
* Copyright 2020, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -95,7 +95,7 @@ type VisitorAttribute struct {

// Snapshot represents a snapshot of a visitor
type Snapshot struct {
Decisions []Decision `json:"decisions"`
Decisions []Decision `json:"decisions,omitempty"`
Events []SnapshotEvent `json:"events"`
}

Expand Down
86 changes: 86 additions & 0 deletions pkg/event/events_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/****************************************************************************
* Copyright 2020, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/

// Package event //
package event

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
)

func TestSnapshotHasOptionalDecisions(t *testing.T) {
snapshot := Snapshot{
Decisions: []Decision{
Decision{
VariationID: "1",
},
},
}

// Check with decisions
jsonValue, err := json.Marshal(snapshot)
assert.Nil(t, err)

dict := map[string]interface{}{}
err = json.Unmarshal(jsonValue, &dict)
assert.Nil(t, err)
_, ok := dict["decisions"]
assert.True(t, ok)

// Check without decisions
snapshot.Decisions = nil
jsonValue, err = json.Marshal(snapshot)
assert.Nil(t, err)

dict2 := map[string]interface{}{}
err = json.Unmarshal(jsonValue, &dict2)
assert.Nil(t, err)
_, ok = dict2["decisions"]
assert.False(t, ok)
}

func TestSnapshotHasNonOptionalEvents(t *testing.T) {
snapshot := Snapshot{
Events: []SnapshotEvent{
SnapshotEvent{
EntityID: "1",
},
},
}

// Check with events
jsonValue, err := json.Marshal(snapshot)
assert.Nil(t, err)

dict := map[string]interface{}{}
err = json.Unmarshal(jsonValue, &dict)
assert.Nil(t, err)
_, ok := dict["events"]
assert.True(t, ok)

// Check without events
snapshot.Events = nil
jsonValue, err = json.Marshal(snapshot)
assert.Nil(t, err)

dict2 := map[string]interface{}{}
err = json.Unmarshal(jsonValue, &dict2)
assert.Nil(t, err)
_, ok = dict2["events"]
assert.True(t, ok)
}
4 changes: 2 additions & 2 deletions pkg/event/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package event

// Version is the current version of the client
const Version = "1.0.0"
var Version = "1.0.0"

// ClientName is the name of the client
const ClientName = "go-sdk"
var ClientName = "go-sdk"

0 comments on commit 67eec57

Please sign in to comment.