Skip to content

Commit

Permalink
add redis project
Browse files Browse the repository at this point in the history
  • Loading branch information
jandre committed Jul 28, 2015
1 parent 2733cf4 commit fa2d15d
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ You can also email me directly: [[email protected]](mailto:jandre+bo
Projects are organized into 'basic' and 'advanced'. Basic tests require very little experience and will walk you through the types of tests to create, the
advanced tests are more free form (although some guidance is provided).

Projects are listed below with also some basic background of knowledge/content to best prepare you to write the tests:
Projects are listed below roughly in order of least -> most difficult, also included is some basic background of knowledge/content you should have to be able to
successfully write the tests:

#### Basic
* [timeago](/projects/basic/timeago) - no knowledge required
* [gocsv](/projects/basic/go-csv) - knowledge of CSV files
* [go-notify](/projects/basic/go-notify) - basic knowledge channels, goroutines
* [gocsv](/projects/basic/go-csv) - knowledge of CSV files helpful
* [go-notify](/projects/basic/go-notify) - basic knowledge of channels, goroutines helpful
* [passwd](/projects/basic/passwd) - knowledge of /etc/passwd files format (nice but not required)
* [sshconfig](/projects/basic/sshconfig) - knowledge of ~/.ssh/config files format (nice but not required)
* [redis](/projects/basic/redis) - some knowledge of Redis helpful

#### Advanced
* [short](/projects/advanced/short) - testing a web app with redis
Expand Down
16 changes: 16 additions & 0 deletions projects/basic/redis/1-test-cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Write test clean up data

*Difficulty Level: Easy*

1. :star2: In `redis_test.go`, create a function that cleans data by calling `client.Flush(false)`

```
func FlushData() {
// TODO your flush code here
}
```

1. :star2: Verify that no error is returned.

1. :star2: Ensure this runs in `TestMain` before the test suite is run.

17 changes: 17 additions & 0 deletions projects/basic/redis/2-test-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Write a test for Flush() and Keys()

*Difficulty Level: Medium*

1. :star2: In `redis_test.go`, create a test `TestFlushReturnsNoKeys`

```
func TestFlushReturnsNoKeys() {
// TODO your test code here
}
```

1. :star2: In `TestFlushReturnsNoKeys`, use the `Set` command to write some data (see [example](https://github.com/hoisie/redis/blob/master/redis_test.go#L33-L37)). Verify no error is returned.

1. :star2: In the same method, call `client.Flush(false)` (code [here](https://github.com/hoisie/redis/blob/master/redis.go#L458-L470)) and verify that no error is returned.

1. :star2: In the same method, call `client.Keys()` and verify no data is returned and no error is returned (code is [here](https://github.com/hoisie/redis/blob/master/redis.go#L374-L394)).
19 changes: 19 additions & 0 deletions projects/basic/redis/3-test-randomkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Write a test for Randomkey()

*Difficulty Level: Easy*

1. :star2: In `redis_test.go`, create a `TestRandomkey` function

```
func TestRandomkey() {
// TODO your test code here
}
```

1. :star2: `Flush` the db and verify no error is returned.

1. :star2: In `TestRandomkey`, use the `Set` command to write some data (see [example](https://github.com/hoisie/redis/blob/master/redis_test.go#L33-L37)). Verify no error is returned.

1. :star2: Call `client.Randomkey()` (code [here](https://github.com/hoisie/redis/blob/master/redis.go#L396-L402)) and verify that no error is returned, and the row you inserted in the previous
step is found.

22 changes: 22 additions & 0 deletions projects/basic/redis/4-test-rename.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Verify Rename() renames a key

*Difficulty Level: Medium*

1. :star2: In `redis_test.go`, create a `TestRenameChangesKey` function to test the renaming of a key.

```
func TestRenameChangesKey() {
// TODO your test code here
}
```

1. :star2: `Flush` the db and verify no error is returned.

1. :star2: In `TestRenameChangesKey`, use the `Set` command to write some data to the "hello-world" key (see [example](https://github.com/hoisie/redis/blob/master/redis_test.go#L33-L37)). Verify no error is returned.

1. :star2: Call `client.Rename("hello-world", "goodbye-world")` to rename hello-world to goodbye-world (code [here](https://github.com/hoisie/redis/blob/master/redis.go#L404-L410)) and verify that no error is returned.

1. :star2: Use the `Get()` command to verify that "goodbye-world" exists



111 changes: 111 additions & 0 deletions projects/basic/redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# redis

## Overview

`redis` provides a Go client API for redis. The Redis API is well documented here: [http://redis.io/commands](http://redis.io/commands)

```
package main
import "github.com/hoisie/redis"
func main() {
var client redis.Client
var key = "hello"
client.Set(key, []byte("world"))
val, _ := client.Get("hello")
println(key, string(val))
}
```

We'll write some tests that cover API calls not covered in the test suite.


## Step 1: Project Setup

1. :star2: Fork the Github project [https://github.com/hoisie/redis](https://github.com/hoisie/redis).

* :question: If you need help, please see [this document](https://help.github.com/articles/fork-a-repo/) or ask a TA for help.

1. :star2: Clone your fork of your repo to your $GOPATH source path.

```bash
cd $GOPATH/src
mkdir -p github.com/<youraccount>
cd github.com/<youraccount>
git clone [email protected]:<youraccount>/redis.git
cd redis
```

1. :star2: Run `go get -v .` to install the dependencies for the `redis` package.

1. :star2: In order to run the webserver, you need to have redis installed. Install redis and make sure it is started and listening on 6379.

```
$ redis-server
~ $ redis-server ~ 130 ↵
[24304] 28 Jul 15:47:13.004 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[24304] 28 Jul 15:47:13.006 * Max number of open files set to 10032
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.6.10 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 24304
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[24304] 28 Jul 15:47:13.007 # Server started, Redis version 2.6.10
[24304] 28 Jul 15:47:13.007 * DB loaded from disk: 0.000 seconds
[24304] 28 Jul 15:47:13.007 * The server is now ready to accept connections on port 6379
```

1. :star2: Run `go test -v .` to ensure that the test run.

You should see something like this:

```bash
redis (master) $ go test -v .
set paste
redis (master) $ go test -v . ~GOPATH/src/github.com/hoisie/redis
=== RUN TestBasic-2
--- PASS: TestBasic-2 (0.00s)
=== RUN TestEmptyGet-2
--- PASS: TestEmptyGet-2 (0.00s)
=== RUN TestConcurrent-2
--- PASS: TestConcurrent-2 (0.00s)
=== RUN TestSet-2
--- PASS: TestSet-2 (0.00s)
=== RUN TestList-2
--- PASS: TestList-2 (0.00s)
=== RUN TestLrem-2
--- PASS: TestLrem-2 (0.00s)
=== RUN TestBrpop-2
--- PASS: TestBrpop-2 (0.00s)
=== RUN TestBlpop-2
--- PASS: TestBlpop-2 (0.00s)
=== RUN TestBrpopTimeout-2
--- PASS: TestBrpopTimeout-2 (1.05s)
=== RUN TestBlpopTimeout-2
--- PASS: TestBlpopTimeout-2 (2.00s)
=== RUN TestSortedSet-2
--- PASS: TestSortedSet-2 (0.01s)
=== RUN TestHash-2
--- PASS: TestHash-2 (0.00s)
=== RUN TestHmset-2
--- PASS: TestHmset-2 (0.00s)
PASS
ok github.com/hoisie/redis 3.074s
```

* :question: If you need help getting the project tests to run, ask your TA.

0 comments on commit fa2d15d

Please sign in to comment.