fixed an issue with first run license validation, tests added
This commit is contained in:
parent
890f7461ab
commit
dc76d2314b
2
go.mod
2
go.mod
|
@ -9,7 +9,7 @@ require (
|
||||||
github.com/lunixbochs/vtclean v1.0.0
|
github.com/lunixbochs/vtclean v1.0.0
|
||||||
github.com/mattn/go-runewidth v0.0.4
|
github.com/mattn/go-runewidth v0.0.4
|
||||||
github.com/mbndr/figlet4go v0.0.0-20190224160619-d6cef5b186ea
|
github.com/mbndr/figlet4go v0.0.0-20190224160619-d6cef5b186ea
|
||||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
|
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22
|
gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22
|
||||||
)
|
)
|
||||||
|
|
|
@ -42,6 +42,8 @@ func GetLicense() *License {
|
||||||
|
|
||||||
func SaveLicense(license License) {
|
func SaveLicense(license License) {
|
||||||
|
|
||||||
|
initStorage()
|
||||||
|
|
||||||
file, err := yaml.Marshal(license)
|
file, err := yaml.Marshal(license)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to marshal license file: %v", err)
|
log.Fatalf("Failed to marshal license file: %v", err)
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package metadata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_getEmptyLicense(t *testing.T) {
|
||||||
|
|
||||||
|
cleanupPlatformStorage()
|
||||||
|
license := GetLicense()
|
||||||
|
|
||||||
|
if license != nil {
|
||||||
|
t.Errorf("expected to be nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_saveAndGetExistingLicense(t *testing.T) {
|
||||||
|
|
||||||
|
cleanupPlatformStorage()
|
||||||
|
|
||||||
|
original := License{
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveLicense(original)
|
||||||
|
|
||||||
|
retrieved := *GetLicense()
|
||||||
|
|
||||||
|
if original != retrieved {
|
||||||
|
t.Errorf("read file != saved file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanupPlatformStorage() {
|
||||||
|
_ = os.RemoveAll(getPlatformStoragePath(""))
|
||||||
|
_ = os.Remove(getPlatformStoragePath(""))
|
||||||
|
}
|
Loading…
Reference in New Issue