Skip to content

Commit

Permalink
Merge 19ce527 into 37d1916
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirfolio3 committed Oct 24, 2019
2 parents 37d1916 + 19ce527 commit c8d8b4c
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 42 deletions.
Empty file removed tests/go.mod
Empty file.
2 changes: 2 additions & 0 deletions tests/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func FeatureContext(s *godog.Suite) {
s.Step(`^the result should match list "([^"]*)"$`, context.TheResultShouldMatchList)
s.Step(`^in the response, "([^"]*)" should be "([^"]*)"$`, context.InTheResponseKeyShouldBeObject)
s.Step(`^in the response, "([^"]*)" should match$`, context.InTheResponseShouldMatch)
s.Step(`^in the response, "([^"]*)" should have this exactly (\d+) times$`, context.ResponseShouldHaveThisExactlyNTimes)
s.Step(`^in the response, "([^"]*)" should have each one of these$`, context.InTheResponseShouldHaveEachOneOfThese)
s.Step(`^the number of dispatched events is (\d+)$`, context.TheNumberOfDispatchedEventsIs)
s.Step(`^there are no dispatched events$`, context.ThereAreNoDispatchedEvents)
s.Step(`^dispatched events payloads include$`, context.DispatchedEventsPayloadsInclude)
}
27 changes: 27 additions & 0 deletions tests/integration/models/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,30 @@ const EventProcessorDefaultQueueSize = 1

// EventProcessorDefaultFlushInterval - The default value for event processor flush interval
const EventProcessorDefaultFlushInterval = 250 * time.Millisecond

// SDKAPI - represents api's of sdk
type SDKAPI string

const (
// IsFeatureEnabled - the api type is IsFeatureEnabled
IsFeatureEnabled SDKAPI = "is_feature_enabled"
// GetFeatureVariable - the api type is GetFeatureVariable
GetFeatureVariable SDKAPI = "get_feature_variable"
// GetFeatureVariableInteger - the api type is GetFeatureVariableInteger
GetFeatureVariableInteger SDKAPI = "get_feature_variable_integer"
// GetFeatureVariableDouble - the api type is GetFeatureVariableDouble
GetFeatureVariableDouble SDKAPI = "get_feature_variable_double"
// GetFeatureVariableBoolean - the api type is GetFeatureVariableBoolean
GetFeatureVariableBoolean SDKAPI = "get_feature_variable_boolean"
// GetFeatureVariableString - the api type is GetFeatureVariableString
GetFeatureVariableString SDKAPI = "get_feature_variable_string"
// GetEnabledFeatures - the api type is GetEnabledFeatures
GetEnabledFeatures SDKAPI = "get_enabled_features"
// GetVariation - the api type is GetVariation
GetVariation SDKAPI = "get_variation"
// Activate - the api type is Activate
Activate SDKAPI = "activate"
)

// KeyListenerCalled - Key for listener called
const KeyListenerCalled = "listener_called"
24 changes: 24 additions & 0 deletions tests/integration/models/get_variation_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/****************************************************************************
* Copyright 2019, 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 models

// GetVariationRequestParams represents params required for GetVariation API
type GetVariationRequestParams struct {
ExperimentKey string `yaml:"experiment_key"`
UserID string `yaml:"user_id"`
Attributes map[string]interface{} `yaml:"attributes"`
}
41 changes: 31 additions & 10 deletions tests/integration/optlyplugins/test_composite_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,9 @@ func (c *TestCompositeService) decisionNotificationCallback(notification notific

func getDecisionInfoForNotification(notification notification.DecisionNotification) map[string]interface{} {
decisionInfoDict := make(map[string]interface{})
switch notificationType := notification.Type; notificationType {
case "feature":
decisionInfoDict = notification.DecisionInfo["feature"].(map[string]interface{})
source := ""
if decisionSource, ok := decisionInfoDict["source"].(decision.Source); ok {
source = string(decisionSource)
} else {
source = decisionInfoDict["source"].(string)
}
decisionInfoDict["source"] = source

updateSourceInfo := func(source string) {
decisionInfoDict["source_info"] = make(map[string]interface{})
if source == "feature-test" {
if sourceInfo, ok := notification.DecisionInfo["source_info"].(map[string]interface{}); ok {
if experimentKey, ok := sourceInfo["experiment_key"].(string); ok {
Expand All @@ -93,7 +85,36 @@ func getDecisionInfoForNotification(notification notification.DecisionNotificati
}
}
}
}

switch notificationType := notification.Type; notificationType {
case "ab-test", "feature-test":
decisionInfoDict["experiment_key"] = notification.DecisionInfo["experimentKey"]
decisionInfoDict["variation_key"] = notification.DecisionInfo["variationKey"]
break
case "feature":
decisionInfoDict = notification.DecisionInfo["feature"].(map[string]interface{})
source := ""
if decisionSource, ok := decisionInfoDict["source"].(decision.Source); ok {
source = string(decisionSource)
} else {
source = decisionInfoDict["source"].(string)
}
decisionInfoDict["source"] = source
updateSourceInfo(source)
case "feature-variable":
decisionInfoDict = notification.DecisionInfo["feature"].(map[string]interface{})
source := ""
if decisionSource, ok := decisionInfoDict["source"].(decision.Source); ok {
source = string(decisionSource)
} else {
source = decisionInfoDict["source"].(string)
}
decisionInfoDict["source"] = source
decisionInfoDict["variable_key"] = notification.DecisionInfo["variable_key"]
decisionInfoDict["variable_type"] = notification.DecisionInfo["variable_type"]
decisionInfoDict["variable_value"] = notification.DecisionInfo["variable_value"]
updateSourceInfo(source)
default:
}
return decisionInfoDict
Expand Down
61 changes: 50 additions & 11 deletions tests/integration/support/client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"path"
"path/filepath"
"strings"

"github.com/optimizely/go-sdk/pkg/client"
"github.com/optimizely/go-sdk/pkg/config"
Expand Down Expand Up @@ -89,28 +88,34 @@ func (c *ClientWrapper) InvokeAPI(request models.APIOptions) (models.APIResponse
var response models.APIResponse
var err error

switch request.APIName {
case "is_feature_enabled":
switch models.SDKAPI(request.APIName) {
case models.IsFeatureEnabled:
response, err = c.isFeatureEnabled(request)
break
case "get_feature_variable":
case models.GetFeatureVariable:
response, err = c.getFeatureVariable(request)
break
case "get_feature_variable_integer":
case models.GetFeatureVariableInteger:
response, err = c.getFeatureVariableInteger(request)
break
case "get_feature_variable_double":
case models.GetFeatureVariableDouble:
response, err = c.getFeatureVariableDouble(request)
break
case "get_feature_variable_boolean":
case models.GetFeatureVariableBoolean:
response, err = c.getFeatureVariableBoolean(request)
break
case "get_feature_variable_string":
case models.GetFeatureVariableString:
response, err = c.getFeatureVariableString(request)
break
case "get_enabled_features":
case models.GetEnabledFeatures:
response, err = c.getEnabledFeatures(request)
break
case models.GetVariation:
response, err = c.getVariation(request)
break
case models.Activate:
response, err = c.activate(request)
break
default:
break
}
Expand Down Expand Up @@ -230,15 +235,49 @@ func (c *ClientWrapper) getEnabledFeatures(request models.APIOptions) (models.AP
var response models.APIResponse
err := yaml.Unmarshal([]byte(request.Arguments), &params)
if err == nil {
enabledFeatures := ""
var enabledFeatures []string
user := entities.UserContext{
ID: params.UserID,
Attributes: params.Attributes,
}
if values, err := c.Client.GetEnabledFeatures(user); err == nil {
enabledFeatures = strings.Join(values, ",")
enabledFeatures = values
}
response.Result = enabledFeatures
}
return response, err
}

func (c *ClientWrapper) getVariation(request models.APIOptions) (models.APIResponse, error) {
var params models.GetVariationRequestParams
var response models.APIResponse
err := yaml.Unmarshal([]byte(request.Arguments), &params)
if err == nil {
user := entities.UserContext{
ID: params.UserID,
Attributes: params.Attributes,
}
response.Result, _ = c.Client.GetVariation(params.ExperimentKey, user)
if response.Result == "" {
response.Result = "NULL"
}
}
return response, err
}

func (c *ClientWrapper) activate(request models.APIOptions) (models.APIResponse, error) {
var params models.GetVariationRequestParams
var response models.APIResponse
err := yaml.Unmarshal([]byte(request.Arguments), &params)
if err == nil {
user := entities.UserContext{
ID: params.UserID,
Attributes: params.Attributes,
}
response.Result, _ = c.Client.Activate(params.ExperimentKey, user)
if response.Result == "" {
response.Result = "NULL"
}
}
return response, err
}

0 comments on commit c8d8b4c

Please sign in to comment.