forked from exercism/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercism_test.go
More file actions
66 lines (51 loc) · 1.45 KB
/
exercism_test.go
File metadata and controls
66 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"github.com/exercism/cli/configuration"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)
func asserFileDoesNotExist(t *testing.T, filename string) {
_, err := os.Stat(filename)
if err == nil {
t.Errorf("File [%s] already exist.", filename)
}
}
func TestLogoutDeletesConfigFile(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "")
assert.NoError(t, err)
c := configuration.Config{}
configuration.ToFile(tmpDir, c)
logout(tmpDir)
asserFileDoesNotExist(t, configuration.Filename(tmpDir))
}
func TestAskForConfigInfoAllowsSpaces(t *testing.T) {
oldStdin := os.Stdin
dirName := "dirname with spaces"
userName := "TestUsername"
apiKey := "abc123"
fakeStdin, err := ioutil.TempFile("", "stdin_mock")
assert.NoError(t, err)
fakeStdin.WriteString(fmt.Sprintf("%s\r\n%s\r\n%s\r\n", userName, apiKey, dirName))
assert.NoError(t, err)
file, err := os.Open(fakeStdin.Name())
defer file.Close()
os.Stdin = file
c, err := askForConfigInfo()
if err != nil {
t.Errorf("Error asking for configuration info [%v]", err)
}
os.Stdin = oldStdin
absoluteDirName, _ := absolutePath(dirName)
_, err = os.Stat(absoluteDirName)
if err != nil {
t.Errorf("Excercism directory [%s] was not created.", absoluteDirName)
}
os.Remove(absoluteDirName)
os.Remove(fakeStdin.Name())
assert.Equal(t, c.ExercismDirectory, absoluteDirName)
assert.Equal(t, c.GithubUsername, userName)
assert.Equal(t, c.ApiKey, apiKey)
}