Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/coverage.out
coverage.out
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
lint:
golint lib && golint lib/internal/models && golint lib/internal/utils && golint lib/internal/messages && golint lib/internal/constants && golint examples
golint lib && golint lib/models && golint lib/internal/utils && golint lib/internal/messages && golint lib/internal/constants && golint examples

testLib:
cd lib/ && go test -coverprofile=coverage.out

testLibModels:
cd lib/internal/models && go test -coverprofile=coverage.out
cd lib/models && go test -coverprofile=coverage.out

testLibUtils:
cd lib/internal/utils && go test -coverprofile=coverage.out
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/robfig/cron v1.2.0
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/text v0.3.6 // indirect
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
Expand Down
9 changes: 8 additions & 1 deletion lib/AppConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ import (
"os"

"github.com/IBM/appconfiguration-go-sdk/lib/internal/messages"
"github.com/IBM/appconfiguration-go-sdk/lib/internal/models"
"github.com/IBM/appconfiguration-go-sdk/lib/internal/utils/log"
"github.com/IBM/appconfiguration-go-sdk/lib/models"
)

// AppConfigurationInterface contains methods used to interact with certain app configuration services
// IMPORTANT: Any change in this interface requires re-generation of mocks using command "$GOPATH/bin/mockery -name AppConfigurationInterface"
type AppConfigurationInterface interface {
GetFeature(featureID string) (models.Feature, error)
GetFeatures() (map[string]models.Feature, error)
}

// AppConfiguration : Struct having init and configInstance.
type AppConfiguration struct {
isInitialized bool
Expand Down
11 changes: 6 additions & 5 deletions lib/ConfigurationHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ import (
"bytes"
"encoding/json"
"errors"
"net/http"
"path"
"sync"
"time"

"github.com/IBM/appconfiguration-go-sdk/lib/internal/constants"
"github.com/IBM/appconfiguration-go-sdk/lib/internal/messages"
"github.com/IBM/appconfiguration-go-sdk/lib/internal/models"
"github.com/IBM/appconfiguration-go-sdk/lib/internal/utils"
"github.com/IBM/appconfiguration-go-sdk/lib/internal/utils/log"
"github.com/IBM/appconfiguration-go-sdk/lib/models"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/gorilla/websocket"
"net/http"
"path"
"sync"
"time"
)

type configurationUpdateListenerFunc func()
Expand Down
21 changes: 9 additions & 12 deletions lib/appconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package lib
import (
"testing"

"github.com/IBM/appconfiguration-go-sdk/lib/internal/models"
"github.com/IBM/appconfiguration-go-sdk/lib/models"
// "github.com/IBM/appconfiguration-go-sdk/lib/internal/utils/log"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -87,14 +87,13 @@ func TestSetContext(t *testing.T) {
ac.isInitialized = true
ac.SetContext("c1", "dev", ContextOptions{
BootstrapFile: "saflights/flights.json",
LiveConfigUpdateEnabled: &F,
LiveConfigUpdateEnabled: F,
}, ContextOptions{
BootstrapFile: "saflights/flights.json",
LiveConfigUpdateEnabled: &F,
LiveConfigUpdateEnabled: F,
})
if hook.LastEntry().Message != "AppConfiguration - Incorrect usage of context options. At most of one ContextOptions struct should be passed." {
t.Errorf("Test failed: Incorrect error message")
}

assert.Equal(t, hook.LastEntry().Message, "AppConfiguration - Incorrect usage of context options. At most of one ContextOptions struct should be passed.")
reset(ac)

// when collection id and environment id is provided successfully and the number of context options is 1. (Bootstrap file evaluation)
Expand All @@ -103,7 +102,7 @@ func TestSetContext(t *testing.T) {
assert.Equal(t, false, ac.isInitializedConfig)
ac.SetContext("c1", "dev", ContextOptions{
BootstrapFile: "saflights/flights.json",
LiveConfigUpdateEnabled: &F,
LiveConfigUpdateEnabled: F,
})
assert.Equal(t, true, ac.isInitializedConfig)
reset(ac)
Expand All @@ -113,12 +112,10 @@ func TestSetContext(t *testing.T) {
ac.isInitialized = true
assert.Equal(t, false, ac.isInitializedConfig)
ac.SetContext("c1", "dev", ContextOptions{
BootstrapFile: "",
LiveConfigUpdateEnabled: &F,
ConfigurationFile: "",
LiveConfigUpdateEnabled: F,
})
if hook.LastEntry().Message != "AppConfiguration - Provide configuration_file value when live_config_update_enabled is false." {
t.Errorf("Test failed: Incorrect error message")
}
assert.Equal(t, hook.LastEntry().Message, "AppConfiguration - Provide bootstrap_file value when live_config_update_enabled is false.")
reset(ac)
}
func TestGetFeature(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions lib/configurationhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"testing"
"time"

"github.com/IBM/appconfiguration-go-sdk/lib/internal/models"
"github.com/IBM/appconfiguration-go-sdk/lib/internal/utils"
"github.com/IBM/appconfiguration-go-sdk/lib/internal/utils/log"
"github.com/IBM/appconfiguration-go-sdk/lib/models"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus/hooks/test"
Expand All @@ -54,7 +54,7 @@ func TestConfigHandlerSetContext(t *testing.T) {
ch := GetConfigurationHandlerInstance()
ch.SetContext("c1", "dev", ContextOptions{
BootstrapFile: "flights.json",
LiveConfigUpdateEnabled: &F,
LiveConfigUpdateEnabled: F,
})
assert.Equal(t, "c1", ch.collectionID)
assert.Equal(t, "dev", ch.environmentID)
Expand Down
57 changes: 57 additions & 0 deletions lib/mocks/AppConfigurationInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions lib/internal/models/Feature.go → lib/models/Feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ import (
"github.com/IBM/appconfiguration-go-sdk/lib/internal/utils/log"
)

// FeatureInterface contains methods used to interact with certain app configuration feature services
// IMPORTANT: Any change in this interface requires re-generation of mocks using command "$GOPATH/bin/mockery -name FeatureInterface"
type FeatureInterface interface {
GetFeatureName() string
GetDisabledValue() interface{}
GetEnabledValue() interface{}
GetFeatureID() string
GetFeatureDataType() string
GetFeatureDataFormat() string
IsEnabled() bool
GetSegmentRules() []SegmentRule
GetCurrentValue(entityID string, entityAttributes map[string]interface{}) interface{}
}

// Feature : Feature struct
type Feature struct {
Name string `json:"name"`
Expand All @@ -38,6 +52,11 @@ type Feature struct {
Enabled bool `json:"enabled"`
}

// NewFeature : New object used for mocking
func NewFeature() FeatureInterface {
return &Feature{}
}

// GetFeatureName : Get Feature Name
func (f *Feature) GetFeatureName() string {
return f.Name
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
147 changes: 147 additions & 0 deletions lib/models/mocks/FeatureInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.