Vova Tkach 6 years ago
parent
commit
951d3190e7
2 changed files with 9 additions and 4 deletions
  1. 5 1
      session/session.go
  2. 4 3
      session/session_test.go

+ 5 - 1
session/session.go

@@ -100,5 +100,9 @@ func (this *Session) Destroy() error {
 	if this.d == "" || this.i == "" {
 	if this.d == "" || this.i == "" {
 		return nil
 		return nil
 	}
 	}
-	return os.Remove(this.d + string(os.PathSeparator) + this.i)
+	err := os.Remove(this.d + string(os.PathSeparator) + this.i)
+	if err == nil {
+		this.c = false
+	}
+	return err
 }
 }

+ 4 - 3
session/session_test.go

@@ -257,7 +257,7 @@ func TestSessionDestroy(t *testing.T) {
 		sess := New(w, r, "./../tmp")
 		sess := New(w, r, "./../tmp")
 		defer sess.Close()
 		defer sess.Close()
 		if r.URL.Path == "/set" {
 		if r.URL.Path == "/set" {
-			sess.SetBool("some_bool", true)
+			sess.SetInt("some_var", 1)
 			w.Write([]byte(`ok`))
 			w.Write([]byte(`ok`))
 		} else {
 		} else {
 			w.WriteHeader(http.StatusNotFound)
 			w.WriteHeader(http.StatusNotFound)
@@ -288,13 +288,13 @@ func TestSessionDestroy(t *testing.T) {
 		sess := New(w, r, "./../tmp")
 		sess := New(w, r, "./../tmp")
 		defer sess.Close()
 		defer sess.Close()
 		if r.URL.Path == "/get" {
 		if r.URL.Path == "/get" {
-			w.Write([]byte(fmt.Sprintf("%v", sess.GetBool("some_bool", false))))
+			w.Write([]byte(fmt.Sprintf("%v", sess.GetInt("some_var", 0))))
 		} else {
 		} else {
 			w.WriteHeader(http.StatusNotFound)
 			w.WriteHeader(http.StatusNotFound)
 			w.Write([]byte(`404`))
 			w.Write([]byte(`404`))
 		}
 		}
 	}).ServeHTTP(recorder, request)
 	}).ServeHTTP(recorder, request)
-	if recorder.Body.String() != "true" {
+	if recorder.Body.String() != "1" {
 		t.Fatalf("bad body response, not match")
 		t.Fatalf("bad body response, not match")
 	}
 	}
 
 
@@ -309,6 +309,7 @@ func TestSessionDestroy(t *testing.T) {
 		sess := New(w, r, "./../tmp")
 		sess := New(w, r, "./../tmp")
 		defer sess.Close()
 		defer sess.Close()
 		if r.URL.Path == "/get" {
 		if r.URL.Path == "/get" {
+			sess.SetInt("some_var", 2)
 			err := sess.Destroy()
 			err := sess.Destroy()
 			if err == nil {
 			if err == nil {
 				w.Write([]byte(`OK`))
 				w.Write([]byte(`OK`))