Merge pull request #26 from sqshq/first_run_license_validation
Issue with first run license validation
This commit is contained in:
commit
a78d1540fb
2
go.mod
2
go.mod
|
@ -9,7 +9,7 @@ require (
|
|||
github.com/lunixbochs/vtclean v1.0.0
|
||||
github.com/mattn/go-runewidth v0.0.4
|
||||
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
|
||||
gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22
|
||||
)
|
||||
|
|
|
@ -42,6 +42,8 @@ func GetLicense() *License {
|
|||
|
||||
func SaveLicense(license License) {
|
||||
|
||||
initStorage()
|
||||
|
||||
file, err := yaml.Marshal(license)
|
||||
if err != nil {
|
||||
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