diff --git a/docker-compose.yaml b/docker-compose.yaml index 466c9d9..a43a404 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -21,3 +21,6 @@ services: depends_on: - redis - dynamodb-local + environment: + REDIS_HOST: "redis:6379" + DYNAMODB_HOST: "http://dynamodb-local:8000" \ No newline at end of file diff --git a/dynamodb/dynamodb_test.go b/dynamodb/dynamodb_test.go index dc2e81b..1172ac8 100644 --- a/dynamodb/dynamodb_test.go +++ b/dynamodb/dynamodb_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "log" + "os" "reflect" "sync" "testing" @@ -22,11 +23,16 @@ var dynamodbInstance *dynamodb.DynamoDB func DynamodbClient() *dynamodb.DynamoDB { var newLocalDynamodb = func() *dynamodb.DynamoDB { + dynamodbHost, ok := os.LookupEnv("DYNAMODB_HOST") + if !ok { + dynamodbHost = "http://localhost:8000" + } + s, err := session.NewSessionWithOptions(session.Options{ Profile: "dynamodb-local", Config: aws.Config{ Region: aws.String("dev-region"), - Endpoint: aws.String("http://localhost:8000"), + Endpoint: aws.String(dynamodbHost), Credentials: credentials.NewStaticCredentials("dev-key-id", "dev-secret-key", ""), }, }) @@ -60,15 +66,19 @@ func TestDynamoDb(t *testing.T) { items, err := c.BatchGet([]string{key}) + if err != nil { + t.Errorf("Expected 1 item, got none %s", err) + } + if len(items) != 1 { - t.Errorf("Received %v items, expected 1", len(items)) + t.Errorf("Expected 1 items, got %v", len(items)) } var str string json.Unmarshal(items[0].Value, &str) if str != val { - t.Errorf("Received %v (type %v), expected %v (type %v)", str, reflect.TypeOf(str), val, reflect.TypeOf(val)) + t.Errorf("Expected %v (type %v), got %v (type %v), ", str, reflect.TypeOf(str), val, reflect.TypeOf(val)) } fmt.Println(items, str, err) diff --git a/redis/redis_test.go b/redis/redis_test.go index ff06b6a..9d9f850 100644 --- a/redis/redis_test.go +++ b/redis/redis_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "os" "reflect" "sync" "testing" @@ -19,8 +20,13 @@ var redisInstance *redis.Client func RedisClient() *redis.Client { var redisDb = func() (*redis.Client, error) { + redisHost, ok := os.LookupEnv("REDIS_HOST") + if !ok { + redisHost = "localhost:6379" + } + db := redis.NewClient(&redis.Options{ - Addr: "localhost:6379", + Addr: redisHost, Password: "", }) @@ -58,6 +64,10 @@ func TestRedis(t *testing.T) { items, err := c.BatchGet([]string{key}) + if err != nil { + t.Errorf("Expected 1 item, got none %s", err) + } + if len(items) != 1 { t.Errorf("Received %v items, expected 1", len(items)) }