-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vishwas Shashidhar
committed
Apr 24, 2023
1 parent
34899a8
commit b3c5f44
Showing
5 changed files
with
152 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cache | ||
|
||
type localCacheManager struct { | ||
store map[string]interface{} | ||
} | ||
|
||
func (r *localCacheManager) initialize() { | ||
r.store = make(map[string]interface{}) | ||
} | ||
|
||
func (r *localCacheManager) GetStatus() string { | ||
return "UP" | ||
} | ||
|
||
func (r *localCacheManager) Set(key string, val interface{}) error { | ||
r.store[key] = val | ||
return nil | ||
} | ||
|
||
func (r *localCacheManager) Get(key string) (string, error) { | ||
if r.store[key] == nil { | ||
return "", nil | ||
} | ||
return r.store[key].(string), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cache | ||
|
||
import ( | ||
"github.com/adwitiyaio/arka/config" | ||
"github.com/adwitiyaio/arka/constants" | ||
"github.com/adwitiyaio/arka/dependency" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
"testing" | ||
) | ||
|
||
type LocalManagerTestSuite struct { | ||
suite.Suite | ||
ccm Manager | ||
} | ||
|
||
func TestLocalManager(t *testing.T) { | ||
suite.Run(t, new(LocalManagerTestSuite)) | ||
} | ||
|
||
func (ts *LocalManagerTestSuite) SetupSuite() { | ||
dm := dependency.GetManager() | ||
config.Bootstrap(config.ProviderEnvironment, "../test.env") | ||
Bootstrap(ProviderLocal) | ||
ts.ccm = dm.Get(DependencyCacheManager).(Manager) | ||
} | ||
|
||
func (ts *LocalManagerTestSuite) Test_localCacheManager_GetStatus() { | ||
ts.Run("success", func() { | ||
status := ts.ccm.GetStatus() | ||
assert.Equal(ts.T(), constants.SystemStatusUp, status) | ||
}) | ||
} | ||
|
||
func (ts *LocalManagerTestSuite) Test_localCacheManager_Set_Get() { | ||
ts.Run("success", func() { | ||
key := "test_key" | ||
val := "Test Value" | ||
err := ts.ccm.Set(key, val) | ||
require.NoError(ts.T(), err) | ||
result, err := ts.ccm.Get(key) | ||
require.NoError(ts.T(), err) | ||
assert.Equal(ts.T(), val, result) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.