Merge pull request #929 from harshavardhana/pr_out_add_session_tests
Add session context tests
This commit is contained in:
+7
-3
@@ -101,7 +101,9 @@ func clearSession(sid string) {
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to load session ‘%s’, %s", sid, NewIodine(iodine.New(err, nil)))
|
||||
}
|
||||
session.Close()
|
||||
if session != nil {
|
||||
session.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func sessionExecute(s *sessionV2) {
|
||||
@@ -146,12 +148,14 @@ func runSessionCmd(ctx *cli.Context) {
|
||||
if err != nil {
|
||||
console.Fatalln(errInvalidSessionID{id: sid})
|
||||
}
|
||||
|
||||
s, err := loadSessionV2(sid)
|
||||
if err != nil {
|
||||
console.Fatalln(errInvalidSessionID{id: sid})
|
||||
}
|
||||
|
||||
// extra check for testing purposes
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
savedCwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
console.Fatalln("Unable to verify your current working folder. %s\n", err)
|
||||
|
||||
+9
-6
@@ -29,8 +29,8 @@ import (
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// migrateSessionV1ToV2 migrates all session files from v1 to v2. This
|
||||
// function should be called from the main early on.
|
||||
// migrateSessionV1ToV2 migrates all session files from v1 to v2.
|
||||
// This function should be called from the main early on.
|
||||
func migrateSessionV1ToV2() {
|
||||
for _, sid := range getSessionIDsV1() {
|
||||
err := os.Remove(getSessionFileV1(sid))
|
||||
@@ -40,6 +40,7 @@ func migrateSessionV1ToV2() {
|
||||
}
|
||||
}
|
||||
|
||||
// sessionV2Header
|
||||
type sessionV2Header struct {
|
||||
Version string `json:"version"`
|
||||
When time.Time `json:"time"`
|
||||
@@ -51,6 +52,7 @@ type sessionV2Header struct {
|
||||
TotalObjects int `json:"total-objects"`
|
||||
}
|
||||
|
||||
// sessionV2
|
||||
type sessionV2 struct {
|
||||
Header *sessionV2Header
|
||||
SessionID string
|
||||
@@ -59,7 +61,7 @@ type sessionV2 struct {
|
||||
sigCh bool
|
||||
}
|
||||
|
||||
// provides a new session
|
||||
// newSessionV2 provides a new session
|
||||
func newSessionV2() *sessionV2 {
|
||||
if !isMcConfigExists() {
|
||||
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
|
||||
@@ -81,11 +83,12 @@ func newSessionV2() *sessionV2 {
|
||||
return s
|
||||
}
|
||||
|
||||
// String printer for SessionV2
|
||||
func (s sessionV2) Info() {
|
||||
console.Infoln("Session terminated. To resume session type ‘mc session resume " + s.SessionID + "’")
|
||||
console.Infoln("Session terminated. To resume session ‘mc session resume " + s.SessionID + "’")
|
||||
}
|
||||
|
||||
// NewDataReader provides reader interface to session data file.
|
||||
// HasData provides true if this is a session resume, false otherwise.
|
||||
func (s sessionV2) HasData() bool {
|
||||
if s.Header.LastCopied == "" {
|
||||
return false
|
||||
@@ -107,7 +110,7 @@ func (s *sessionV2) NewDataWriter() io.Writer {
|
||||
return io.Writer(s.DataFP)
|
||||
}
|
||||
|
||||
// save this session
|
||||
// Save this session
|
||||
func (s *sessionV2) Save() error {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@@ -48,3 +50,37 @@ func (s *CmdTestSuite) TestSession(c *C) {
|
||||
err = session.Close()
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *CmdTestSuite) TestSessionContext(c *C) {
|
||||
err := app.Run([]string{os.Args[0], "session", "list"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
err = app.Run([]string{os.Args[0], "session", "clear", "all"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
err = app.Run([]string{os.Args[0], "session", "resume", "invalid"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
err = app.Run([]string{os.Args[0], "session", "clear", "invalid"})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
console.IsExited = false
|
||||
|
||||
err = createSessionDir()
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(isSessionDirExists(), Equals, true)
|
||||
|
||||
session := newSessionV2()
|
||||
c.Assert(session.Header.CommandArgs, IsNil)
|
||||
c.Assert(len(session.SessionID), Equals, 8)
|
||||
|
||||
err = session.Save()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
err = app.Run([]string{os.Args[0], "session", "clear", session.SessionID})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user