-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_test.go
60 lines (51 loc) · 1.36 KB
/
main_test.go
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
package main
import (
"bytes"
"io"
"io/ioutil"
"testing"
"github.com/aws/aws-sdk-go/service/s3"
)
type fakeS3 struct {
getObjectOutput s3.GetObjectOutput
}
func (f fakeS3) GetObject(i *s3.GetObjectInput) (*s3.GetObjectOutput, error) {
return &f.getObjectOutput, nil
}
func (f fakeS3) ListObjectsPages(i *s3.ListObjectsInput, fn func(p *s3.ListObjectsOutput, lastPage bool) (shouldContinue bool)) error {
return nil
}
func TestReadAuthorizedKeyNewLine(t *testing.T) {
body := "asdfghjkl\n"
svc = &fakeS3{
getObjectOutput: s3.GetObjectOutput{
Body: ioutil.NopCloser(bytes.NewBufferString(body)),
},
}
keys := make(chan io.Reader)
go readAuthorizedKey("bucket", "/a/path", keys)
got, err := ioutil.ReadAll(<-keys)
if err != nil {
t.Errorf("Unable to convert to string: %v", err)
}
if string(got) != body {
t.Errorf("Expected key is wrong: Got: %v, Wanted: %v", got, body)
}
}
func TestReadAuthorizedKeyNoNewLine(t *testing.T) {
body := "asdfghjkl"
svc = &fakeS3{
getObjectOutput: s3.GetObjectOutput{
Body: ioutil.NopCloser(bytes.NewBufferString(body)),
},
}
keys := make(chan io.Reader)
go readAuthorizedKey("bucket", "/a/path", keys)
got, err := ioutil.ReadAll(<-keys)
if err != nil {
t.Errorf("Unable to convert to string: %v", err)
}
if string(got) != body+"\n" {
t.Errorf("Expected key is wrong: Got: %v, Wanted: %v", got, body)
}
}