I am looking to instantiate an object and update the state of this object across multiple function calls in a Go Test.
My main logic looks like this:
type User struct {
Username string
Persist4 map[string]string
}
func Init(username string, password string) (userdataptr *User, err error) {
mapping2 := make(map[string]string)
var userdata User
userdata.Username = username
userdata.Persist5 = mapping2
// Marshak and store this structure
return &userdata, err
}
func Get(uname string, password string) (user *User, err error) {
// Retrieve and unmarshal user into tmp
return &temp, nil
}
func (userdata *User) StoreFile(filename string, data []byte) {
userdata.Persist4['test'] = 'fails' // This is not available in the next call
}
And the testing logic looks like this:
func TestInit(t *testing.T) {
u, _ := Init("a", "f")
}
func TestStorage(t *testing.T) {
u, err := GetUser("a", "f")
u.StoreFile("file1", v)
}
func test(t *testing.T) {
u, err := Get("a", "f")
// u no longer has attribute persist4['test'] = 'fails'
}