package main import ( "log" "testing" "time" ) func TestSession(t *testing.T) { id := "testopenid" procedure := "test procedure" //delete any existing deleteSession(id) path := getSessionPath(id) AssertEqual(t, isFileExist(path), false, "Session file should not exist") //create new setSessionProcedure(id, procedure, 100) //wait 1 sec log.Print("wait for 1 sec for testing timestamp ......") time.Sleep(1 * time.Second) log.Print("......waiting done") //read back , check state s, _ := getCurrentSesssion(id) AssertEqual(t, s.Procedure, procedure, "") now := int32(time.Now().Unix()) //check timing AssertEqual(t, s.Expire > now, true, "Expire should be in future") AssertEqual(t, s.UpdateAt < now, true, "Update should be in pass") AssertEqual(t, s.CreateAt == s.UpdateAt, true, "Update should be equal to create") AssertEqual(t, isExpired(now), false, "current time should not be expired") //update existing session s, _ = setSessionProcedure(id, procedure, 100) //timeing should be exactly 1s diff AssertEqual(t, s.CreateAt+1 == s.UpdateAt, true, "second Update should be bigger create") n, _ := getCurrentSesssion(id) AssertEqual(t, s, n, "session should be equal") //delete session, for clean up deleteSession(id) path = getSessionPath(id) AssertEqual(t, isFileExist(path), false, "Session file should not exist") }