github.com/c3pm-labs/c3pm@v0.3.0/ctpm/logout_test.go (about)

     1  package ctpm_test
     2  
     3  import (
     4  	"github.com/c3pm-labs/c3pm/ctpm"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	"os"
     8  	"path"
     9  )
    10  
    11  var _ = Describe("Logout", func() {
    12  	c3pmHomeDir := getTestFolder("LogoutUserHome")
    13  
    14  	It("should delete auth file", func() {
    15  		err := os.MkdirAll(c3pmHomeDir, os.ModePerm)
    16  		Ω(err).ShouldNot(HaveOccurred())
    17  
    18  		err = os.Setenv("C3PM_USER_DIR", c3pmHomeDir)
    19  		Ω(err).ShouldNot(HaveOccurred())
    20  
    21  		defer os.Unsetenv("C3PM_USER_DIR")
    22  
    23  		authFilePath := path.Join(c3pmHomeDir, "auth.cfg")
    24  		f, err := os.Create(authFilePath)
    25  		Ω(err).ShouldNot(HaveOccurred())
    26  
    27  		err = f.Close()
    28  		Ω(err).ShouldNot(HaveOccurred())
    29  
    30  		err = ctpm.Logout()
    31  		Ω(err).ShouldNot(HaveOccurred())
    32  
    33  		_, err = os.Stat(authFilePath)
    34  		Ω(os.IsNotExist(err)).To(BeTrue())
    35  	})
    36  })