Skip to content

Commit

Permalink
🏁 Test only for error checks
Browse files Browse the repository at this point in the history
	[I] #15, #16
	[T] More elaborated tests for setAutoStart()
	[#] Fixes #15
  • Loading branch information
ChacaS0 committed Apr 8, 2018
1 parent 8d1515f commit b2144f8
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 61 deletions.
56 changes: 3 additions & 53 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func TestInitializeTP(t *testing.T) {
// meaning the reset of it if it already exists
// and its creation if it doesn't exist yet.
func TestInitializeCfFile(t *testing.T) {
// Save current Tempestcf
// Save current Tempestyml
tempestymlOld := Tempestyml
// Set the temporary .tempestcf used for the test
// Set the temporary .tempestyml used for the test
Tempestyml = conf.Gopath + string(os.PathSeparator) + ".tempest.yaml"
// viper.SetConfigFile(Tempestyml)

Expand Down Expand Up @@ -134,7 +134,7 @@ func cleanTempest(t *testing.T, tempest *string, tempestOld string) (errReturn e
t.Log("[ERROR]:: There was an error when trying to delete the freshly created file")
}

// Restore previous Tempestcf
// Restore previous Tempest
*tempest = tempestOld

return
Expand Down Expand Up @@ -199,53 +199,3 @@ func fbTestTempestcf(t *testing.T, tempestcfbup string) {
}
Tempestcf = tempestcfbup
}

// SameSlices checks equality between two slices of string
// returns true if they are identiques
func SameSlices(a, b []string) bool {
if a == nil && nil == b {
return true
}

if len(a) == 0 && len(b) == 0 {
return true
}

if len(a) != len(b) {
return false
}

b = b[:len(a)]
for i, v := range a {
if v != b[i] {
return false
}
}

return true
}

// SameSlicesInt checks equality between two slices of int
// returns true if they are identiques
func SameSlicesInt(a, b []int) bool {
if a == nil && nil == b {
return true
}

if len(a) == 0 && len(b) == 0 {
return true
}

if len(a) != len(b) {
return false
}

b = b[:len(a)]
for i, v := range a {
if v != b[i] {
return false
}
}

return true
}
50 changes: 50 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,53 @@ func WriteLog(pathLog string, strs ...string) {
}
}
}

// SameSlices checks equality between two slices of string
// returns true if they are identiques
func SameSlices(a, b []string) bool {
if a == nil && nil == b {
return true
}

if len(a) == 0 && len(b) == 0 {
return true
}

if len(a) != len(b) {
return false
}

b = b[:len(a)]
for i, v := range a {
if v != b[i] {
return false
}
}

return true
}

// SameSlicesInt checks equality between two slices of int
// returns true if they are identiques
func SameSlicesInt(a, b []int) bool {
if a == nil && nil == b {
return true
}

if len(a) == 0 && len(b) == 0 {
return true
}

if len(a) != len(b) {
return false
}

b = b[:len(a)]
for i, v := range a {
if v != b[i] {
return false
}
}

return true
}
2 changes: 1 addition & 1 deletion cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var age int
var autoStart string

// LinuxAutoStartP is the path to $HOME/.config/autostart/tempest.desktop
// which is initiaalized in init()
// which is initialized in init()
var LinuxAutoStartP string

// WindowsAutoStartSL is the path to "%AppData%\Microsoft\Windows\Start Menu\Programs\Startup\tempest".
Expand Down
43 changes: 42 additions & 1 deletion cmd/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,46 @@ auto-mode: false

// TestSetAutoStart tests if it really activates auto start (depends on the device OS)
func TestSetAutoStart(t *testing.T) {
// TODO: Need windows mode to be done too :/
// Save current Tempestyml
tempestymlOld := Tempestyml
// Set the temporary .tempestyml used for the test
Tempestyml = conf.Gopath + string(os.PathSeparator) + ".tempest.yaml"
// viper.SetConfigFile(Tempestyml)

//* Case doesn't exist yet, should create one
err := initializeCfFile()
if err != nil {
t.Log("[ERROR]:: Error while initializing on non-existing .tempest.yml\n\t", err)
t.Fail()
}

//* Linux
// For linux it should create the file ~/.config/autostart/tempest.desktop
// Should be already "off", meaning ``false``.
// Check if no args messes up
if err := setAutoStart(); err != nil {
t.Log("[ERROR]:: An error was encoutered while using setAutostart:\n\t->", err)
}

// Now set it to off
autoStart = "off"
if err := setAutoStart(); err != nil {
t.Log("[ERROR]:: An error was encoutered while using setAutostart:\n\t->", err)
}

// And then to on
autoStart = "on"
if err := setAutoStart(); err != nil {
t.Log("[ERROR]:: An error was encoutered while using setAutostart:\n\t->", err)
}

// TODO Need windows mode to be done too :/
// Maybe try to change the runtime.GOOS ? -- will need to set the env and paths separators for windows !?

// Set back to default conf and clean temp test files
if err = cleanTempest(t, &Tempestyml, tempestymlOld); err != nil {
t.Log("[ERROR]:: An error occurred:", err)
t.Fail()
}
viper.SetConfigFile(Tempestyml)
}
12 changes: 6 additions & 6 deletions list.todo
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ General:
✔ update README.md @today @done (2/5/2018, 3:58:38 AM)
✔ update doc of the commands @today @done (2/5/2018, 4:18:36 AM)
✔ --> git log HEAD..origin/master --oneline @done (2/5/2018, 4:18:44 AM)
[UPDATE] check if can just use ``go get -u`` now instead of pull/fetch @high
OR makefile?
[UPDATE] check if can just use ``go get -u`` now instead of pull/fetch @high @done (4/7/2018, 5:17:00 PM)
OR makefile? @cancelled (4/7/2018, 5:17:05 PM)
✔ remove (+same thing as add with ``this``) @done (3/11/2018, 4:38:55 PM)
✔ list all current paths @done (2/3/2018, 6:34:34 PM)
✔ --> Bonus: there is a yellow number as the index of the line (line number) @done (2/3/2018, 6:39:28 PM)
``cd`` to a number of path for example: ``tempest cd 0``
``cd`` to a number of path for example: ``tempest cd 0`` @cancelled (4/7/2018, 5:17:22 PM)
✔ Start @critical this is the actual stuff : call purge @done (2/4/2018, 4:17:32 PM)
✔ When adding a path check if the path exists -_- @high @done (3/11/2018, 4:38:49 PM)
✔ [ADD] check if it ends with a separator @low @done (3/11/2018, 4:38:47 PM)
Expand All @@ -33,19 +33,19 @@ General:
☐ 0-1
☐ 0 2 4
RM - Command:
build the ``--origin`` flag
build the ``--origin`` flag @done (4/7/2018, 5:17:44 PM)
visual:
✔ use colorized logs (check paper fluo in bag) @done (2/3/2018, 6:34:39 PM)
☐ refractor helpers with color package ? @low
✔ See the current version @low @done (3/4/2018, 3:37:40 PM)
✔ [CURRENT VERSION] [REVISION] Would be the last commit @done (3/11/2018, 4:39:19 PM)
[LATEST VERSION]
[LATEST VERSION] @done (4/7/2018, 5:17:59 PM)
✔ Improve visualisation of output on ``tempest start `` @done (3/11/2018, 4:39:29 PM)
✔ More information when doing ``tempest update`` @today @done (2/10/2018, 12:01:48 PM)

Note:
✘ [UPDATE] go build -o $GOBIN/tempest main.go @cancelled (2/5/2018, 4:13:02 AM)
☐ Use GoRoutines for deletion @high
☐ Use GoRoutines for deletion and lookup @high
✔ THERE IS STILL A BUG ON UPDATE @critical @done (2/5/2018, 4:12:47 AM)
✘ make.sh -> makefile @cancelled (3/4/2018, 3:37:30 PM)
✔ Checkout Jenkins? @done (3/4/2018, 3:37:25 PM)
Expand Down

0 comments on commit b2144f8

Please sign in to comment.