Permalink
Browse files

Implemented the method for listing all statuses

Renamed the `setUp` function in filereader_test.go because within the
same package it's global. So I renamed it and used it for the
statuscrud_file_test.go tests.
  • Loading branch information...
kiriappeee committed May 10, 2018
1 parent cb2b9c7 commit aaa476b2360b3ae549a67a6fa2cd738b0270a249
Showing with 29 additions and 28 deletions.
  1. +24 −23 filereader_test.go
  2. +4 −5 statuscrud_file.go
  3. +1 −0 statuscrud_file_test.go
@@ -5,6 +5,7 @@ import (
"os"
"testing"
)

const dummyStatusList = `
- statusName: lunch
emoji: chompy
@@ -23,10 +24,10 @@ const dummyStatusList = `
statusText: In Focus mode
`

func setUp(){
func fileSetUp() {
homeDirectory := os.Getenv("HOME")
_, err := os.Stat(homeDirectory+"/.config/ssuclitest")
if os.IsNotExist(err){
_, err := os.Stat(homeDirectory + "/.config/ssuclitest")
if os.IsNotExist(err) {
err = os.MkdirAll(homeDirectory+"/.config/ssuclitest", 1)
if err != nil {
log.Fatal(err)
@@ -45,25 +46,25 @@ func setUp(){
}
}

_, err = os.Stat(homeDirectory+"/.config/ssuclitest/config")
if os.IsNotExist(err){
_, err := os.Create(homeDirectory+"/.config/ssuclitest/config")
_, err = os.Stat(homeDirectory + "/.config/ssuclitest/config")
if os.IsNotExist(err) {
_, err := os.Create(homeDirectory + "/.config/ssuclitest/config")
if err != nil {
log.Fatal(err)
}
}
}

func tearDown(){
func fileTearDown() {
homeDirectory := os.Getenv("HOME")
err := os.RemoveAll(homeDirectory+"/.config/ssuclitest")
err := os.RemoveAll(homeDirectory + "/.config/ssuclitest")
if err != nil {
log.Fatal(err)
}
}

func TestIfFileExists(t *testing.T){
setUp()
func TestIfFileExists(t *testing.T) {
fileSetUp()
homeDirectory := os.Getenv("HOME")
fileNameToSearchFor := homeDirectory + "/.config/ssuclitest/statuses.yaml"
statusesToTest, err := getStatusesFromFile(fileNameToSearchFor)
@@ -73,36 +74,36 @@ func TestIfFileExists(t *testing.T){
if len(statusesToTest) != 4 {
t.Fatalf("Length of returned array was %d. Expected 4", len(statusesToTest))
}
tearDown()
fileTearDown()
}

func TestThatDefaultFilesAreSetUp(t *testing.T){
func TestThatDefaultFilesAreSetUp(t *testing.T) {
homeDirectory := os.Getenv("HOME")
err := checkAndSetupConfigDirectory(homeDirectory+"/.config/ssuclitest");
err := checkAndSetupConfigDirectory(homeDirectory + "/.config/ssuclitest")
if err != nil {
t.Fatal("An error occurred. Expected no error. Error was %s", err.Error())
}
_, err = os.Stat(homeDirectory+"/.config/ssuclitest")
if os.IsNotExist(err){
_, err = os.Stat(homeDirectory + "/.config/ssuclitest")
if os.IsNotExist(err) {
t.Fatalf("~/.config/ssuclitest doesn't exist after function call")
}
_, err = os.Stat(homeDirectory+"/.config/ssuclitest/statuses.yaml")
if os.IsNotExist(err){

_, err = os.Stat(homeDirectory + "/.config/ssuclitest/statuses.yaml")
if os.IsNotExist(err) {
t.Fatalf("~/.config/ssuclitest/statuses.yaml doesn't exist after function call")
}
statusesToTest, err := getStatusesFromFile(homeDirectory+"/.config/ssuclitest/statuses.yaml")
statusesToTest, err := getStatusesFromFile(homeDirectory + "/.config/ssuclitest/statuses.yaml")
if err != nil {
t.Fatalf("An error occurred. Expected no error. Error was %s", err.Error())
}
if len(statusesToTest) != 8 {
t.Fatalf("Length of returned array was %d. Expected 8", len(statusesToTest))
}

_, err = os.Stat(homeDirectory+"/.config/ssuclitest/tokenconfig")
if os.IsNotExist(err){
_, err = os.Stat(homeDirectory + "/.config/ssuclitest/tokenconfig")
if os.IsNotExist(err) {
t.Fatalf("~/.config/ssuclitest/tokenconfig doesn't exist after function call")
}

tearDown()
}
fileTearDown()
}
@@ -7,12 +7,11 @@ import (
type statusCRUDFileImplementation string

func (s statusCRUDFileImplementation) GetStatuses() []ssucore.Status {
return []ssucore.Status{
ssucore.Status{"test", "emojiA", "Status One"},
ssucore.Status{"test1", "emojiB", "Status Two"},
ssucore.Status{"test2", "emojiC", "Status Three"},
ssucore.Status{"test3", "emojiD", "Status Four"},
if s != "" {
statuses, _ := getStatusesFromFile(string(s))
return statuses
}
return []ssucore.Status{}
}

func (s statusCRUDFileImplementation) GetStatusByKey(name string) (ssucore.Status, error) {
@@ -8,6 +8,7 @@ import (
)

func TestStatusesCanBeListed(t *testing.T) {
fileSetUp()
var sci ssucore.StatusCRUDInterface
homeDirectory := os.Getenv("HOME")
sci = statusCRUDFileImplementation(homeDirectory + "/.config/ssuclitest/statuses.yaml")

0 comments on commit aaa476b

Please sign in to comment.