func (ls SqlLicenseStore) Save(license *model.LicenseRecord) StoreChannel {

	storeChannel := make(StoreChannel)

	go func() {
		result := StoreResult{}

		license.PreSave()
		if result.Err = license.IsValid(); result.Err != nil {
			storeChannel <- result
			close(storeChannel)
			return
		}

		// Only insert if not exists
		if err := ls.GetReplica().SelectOne(&model.LicenseRecord{}, "SELECT * FROM Licenses WHERE Id = :Id", map[string]interface{}{"Id": license.Id}); err != nil {
			if err := ls.GetMaster().Insert(license); err != nil {
				result.Err = model.NewLocAppError("SqlLicenseStore.Save", "store.sql_license.save.app_error", nil, "license_id="+license.Id+", "+err.Error())
			} else {
				result.Data = license
			}
		}

		storeChannel <- result
		close(storeChannel)
	}()

	return storeChannel
}
func TestLicenseStoreSave(t *testing.T) {
	Setup()

	l1 := model.LicenseRecord{}
	l1.Id = model.NewId()
	l1.Bytes = "junk"

	if err := (<-store.License().Save(&l1)).Err; err != nil {
		t.Fatal("couldn't save license record", err)
	}

	if err := (<-store.License().Save(&l1)).Err; err != nil {
		t.Fatal("shouldn't fail on trying to save existing license record", err)
	}
}
func TestLicenseStoreGet(t *testing.T) {
	Setup()

	l1 := model.LicenseRecord{}
	l1.Id = model.NewId()
	l1.Bytes = "junk"

	Must(store.License().Save(&l1))

	if r := <-store.License().Get(l1.Id); r.Err != nil {
		t.Fatal("couldn't get license", r.Err)
	} else {
		if r.Data.(*model.LicenseRecord).Bytes != l1.Bytes {
			t.Fatal("license bytes didn't match")
		}
	}
}