Skip to content

Commit

Permalink
Save remote config when there is no error (#152)
Browse files Browse the repository at this point in the history
Signed-off-by: Marius Sincovici <[email protected]>
  • Loading branch information
mariusSincovici authored Nov 9, 2023
1 parent 5d43da9 commit 9cf4ae4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/remote/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (rc *RConfig) fetchAndSaveRemoteConfig() (remoteConfig []byte, err error) {
defer func() {
errCfgSave := rc.configManager.SaveWith(func(c config.Config) config.Config {
c.RCLastUpdate = time.Now()
if err != nil {
if err == nil {
c.RemoteConfig = string(remoteConfig)
}
return c
Expand Down
12 changes: 12 additions & 0 deletions config/remote/firebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/NordSecurity/nordvpn-linux/config"
"github.com/NordSecurity/nordvpn-linux/test/category"
"github.com/NordSecurity/nordvpn-linux/test/mock"
"google.golang.org/api/firebaseremoteconfig/v1"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -368,6 +369,17 @@ func TestRemoteConfig_GetCachedData(t *testing.T) {
} else {
assert.NoError(t, err)
}

// check if cache remote config is the same as the fetch
if test.remoteConfig != "" {
var cfgExpected firebaseremoteconfig.RemoteConfig
assert.NoError(t, json.Unmarshal([]byte(test.remoteConfig), &cfgExpected))

var cfg firebaseremoteconfig.RemoteConfig
assert.NoError(t, json.Unmarshal([]byte(cm.Cfg.RemoteConfig), &cfg))

assert.Equal(t, cfgExpected, cfg, "fetch RC different from saved one")
}
})
}
}
Expand Down

0 comments on commit 9cf4ae4

Please sign in to comment.