github.com/wostzone/hub/auth@v0.0.0-20220118060317-7bb375743b17/pkg/configstore/ConfigStore_test.go (about) 1 package configstore_test 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "github.com/wostzone/hub/auth/pkg/configstore" 6 "os" 7 "path" 8 "testing" 9 ) 10 11 var storeFolder = "" 12 13 // TestMain determines the store location 14 // Used for all test cases in this package 15 func TestMain(m *testing.M) { 16 cwd, _ := os.Getwd() 17 homeFolder := path.Join(cwd, "../../test") 18 storeFolder = path.Join(homeFolder, "configStore") 19 20 res := m.Run() 21 os.Exit(res) 22 } 23 24 func TestOpenClose(t *testing.T) { 25 cfgStore := configstore.NewConfigStore(storeFolder) 26 err := cfgStore.Open() 27 assert.NoError(t, err) 28 cfgStore.Close() 29 } 30 31 func TestWriteConfig(t *testing.T) { 32 const user1ID = "user1" 33 const app1ID = "app1" 34 const configData = "Hello world" 35 cfgStore := configstore.NewConfigStore(storeFolder) 36 err := cfgStore.Open() 37 assert.NoError(t, err) 38 39 err = cfgStore.Put(user1ID, app1ID, configData) 40 assert.NoError(t, err) 41 42 rxData := cfgStore.Get(user1ID, app1ID) 43 assert.Equal(t, configData, rxData) 44 cfgStore.Close() 45 } 46 47 func TestReadMissingConfig(t *testing.T) { 48 const user1ID = "user1" 49 const app2ID = "app2" 50 cfgStore := configstore.NewConfigStore(storeFolder) 51 err := cfgStore.Open() 52 assert.NoError(t, err) 53 54 rxData := cfgStore.Get(user1ID, app2ID) 55 assert.Empty(t, rxData) 56 cfgStore.Close() 57 }