diff --git a/go.mod b/go.mod index 60293a7..fdcd5e4 100644 --- a/go.mod +++ b/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 ) diff --git a/metadata/license.go b/metadata/license.go index 0ab75b1..9518017 100644 --- a/metadata/license.go +++ b/metadata/license.go @@ -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) diff --git a/metadata/license_test.go b/metadata/license_test.go new file mode 100644 index 0000000..aeaa1f8 --- /dev/null +++ b/metadata/license_test.go @@ -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("")) +}