• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

optimizely / go-sdk / 16326136479

16 Jul 2025 05:25PM UTC coverage: 91.782%. First build
16326136479

Pull #411

github

Mat001
Trigger PR check
Pull Request #411: [FSSDK-11649] Fix FSC failed tests for CMAB

40 of 43 new or added lines in 5 files covered. (93.02%)

5305 of 5780 relevant lines covered (91.78%)

9971.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.18
/pkg/decision/composite_feature_service.go
1
/****************************************************************************
2
 * Copyright 2019-2020, Optimizely, Inc. and contributors                   *
3
 *                                                                          *
4
 * Licensed under the Apache License, Version 2.0 (the "License");          *
5
 * you may not use this file except in compliance with the License.         *
6
 * You may obtain a copy of the License at                                  *
7
 *                                                                          *
8
 *    http://www.apache.org/licenses/LICENSE-2.0                            *
9
 *                                                                          *
10
 * Unless required by applicable law or agreed to in writing, software      *
11
 * distributed under the License is distributed on an "AS IS" BASIS,        *
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13
 * See the License for the specific language governing permissions and      *
14
 * limitations under the License.                                           *
15
 ***************************************************************************/
16

17
// Package decision //
18
package decision
19

20
import (
21
        "strings"
22

23
        "github.com/optimizely/go-sdk/v2/pkg/decide"
24
        "github.com/optimizely/go-sdk/v2/pkg/entities"
25
        "github.com/optimizely/go-sdk/v2/pkg/logging"
26
)
27

28
// CompositeFeatureService is the default out-of-the-box feature decision service
29
type CompositeFeatureService struct {
30
        featureServices []FeatureService
31
        logger          logging.OptimizelyLogProducer
32
}
33

34
// NewCompositeFeatureService returns a new instance of the CompositeFeatureService
35
func NewCompositeFeatureService(sdkKey string, compositeExperimentService ExperimentService) *CompositeFeatureService {
3✔
36
        return &CompositeFeatureService{
3✔
37
                logger: logging.GetLogger(sdkKey, "CompositeFeatureService"),
3✔
38
                featureServices: []FeatureService{
3✔
39
                        NewFeatureExperimentService(logging.GetLogger(sdkKey, "FeatureExperimentService"), compositeExperimentService),
3✔
40
                        NewRolloutService(sdkKey),
3✔
41
                },
3✔
42
        }
3✔
43
}
3✔
44

45
// GetDecision returns a decision for the given feature and user context
46
func (f CompositeFeatureService) GetDecision(decisionContext FeatureDecisionContext, userContext entities.UserContext, options *decide.Options) (FeatureDecision, decide.DecisionReasons, error) {
5✔
47
        var featureDecision = FeatureDecision{}
5✔
48
        reasons := decide.NewDecisionReasons(options)
5✔
49
        var err error
5✔
50
        for _, featureDecisionService := range f.featureServices {
13✔
51
                var decisionReasons decide.DecisionReasons
8✔
52
                featureDecision, decisionReasons, err = featureDecisionService.GetDecision(decisionContext, userContext, options)
8✔
53
                reasons.Append(decisionReasons)
8✔
54
                if err != nil {
12✔
55
                        f.logger.Debug(err.Error())
4✔
56
                        // Check if this is a CMAB error - if so, stop the loop and return empty decision
4✔
57
                        if strings.Contains(err.Error(), "Failed to fetch CMAB data") {
5✔
58
                                // Add the CMAB error to reasons before returning - use AddError for critical failures
1✔
59
                                reasons.AddError(err.Error())
1✔
60
                                return FeatureDecision{}, reasons, nil // Return empty decision for CMAB errors
1✔
61
                        }
1✔
62
                }
63

64
                // Also check for CMAB errors in decision reasons (when err is nil)
65
                if decisionReasons != nil {
14✔
66
                        for _, reason := range decisionReasons.ToReport() {
7✔
NEW
67
                                if strings.Contains(reason, "Failed to fetch CMAB data") {
×
NEW
68
                                        return FeatureDecision{}, reasons, nil
×
NEW
69
                                }
×
70
                        }
71
                }
72

73
                if featureDecision.Variation != nil && err == nil {
10✔
74
                        return featureDecision, reasons, err
3✔
75
                }
3✔
76
        }
77
        return featureDecision, reasons, err
1✔
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc