Skip to content

Commit

Permalink
#48 fixing missing tests compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mageddo committed May 6, 2018
1 parent f789738 commit d1807b3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 49 deletions.
14 changes: 3 additions & 11 deletions controller/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/mageddo/dns-proxy-server/events/local"
"github.com/mageddo/dns-proxy-server/utils"
"github.com/mageddo/dns-proxy-server/flags"
"github.com/mageddo/go-logging"
)

func TestGetActiveEnvSuccess(t *testing.T) {
Expand Down Expand Up @@ -42,8 +41,7 @@ func TestPutChangeActiveEnvSuccess(t *testing.T) {

defer local.ResetConf()

ctx := logging.NewContext()
local.LoadConfiguration(ctx)
local.LoadConfiguration()

err := utils.WriteToFile(`{
"remoteDnsServers": [], "envs": [{ "name": "testEnv" }]
Expand Down Expand Up @@ -72,12 +70,8 @@ func TestPutChangeActiveEnvSuccess(t *testing.T) {
func TestGetEnvsSuccess(t *testing.T) {

defer local.ResetConf()

ctx := logging.NewContext()
local.LoadConfiguration(ctx)

local.LoadConfiguration()
err := utils.WriteToFile(`{ "remoteDnsServers": [], "envs": [{ "name": "SecondEnv" }]}`, utils.GetPath(*flags.ConfPath))

assert.Nil(t, err)

s := httptest.NewServer(nil)
Expand Down Expand Up @@ -120,9 +114,7 @@ func TestPostEnvSuccess(t *testing.T) {
func TestDeleteEnvSuccess(t *testing.T) {

defer local.ResetConf()

ctx := logging.NewContext()
local.LoadConfiguration(ctx)
local.LoadConfiguration()

err := utils.WriteToFile(`{ "remoteDnsServers": [], "envs": [{ "name": "SecondEnv" }]}`, utils.GetPath(*flags.ConfPath))

Expand Down
20 changes: 5 additions & 15 deletions controller/hostname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import (
"net/http"
"github.com/mageddo/dns-proxy-server/events/local"
"github.com/mageddo/dns-proxy-server/flags"
"github.com/mageddo/go-logging"
"github.com/mageddo/dns-proxy-server/utils"
)

func TestGetHostnamesByEnv(t *testing.T) {

defer local.ResetConf()

ctx := logging.NewContext()
local.LoadConfiguration(ctx)
local.LoadConfiguration()

err := utils.WriteToFile(`{ "remoteDnsServers": [], "envs": [
{ "name": "MyEnv", "hostnames": [{"hostname": "github.io", "ip": [1,2,3,4], "ttl": 55}] }
Expand All @@ -39,9 +36,7 @@ func TestGetHostnamesByEnv(t *testing.T) {
func TestGetHostnamesByEnvAndHostname(t *testing.T) {

defer local.ResetConf()

ctx := logging.NewContext()
local.LoadConfiguration(ctx)
local.LoadConfiguration()

err := utils.WriteToFile(`{ "remoteDnsServers": [], "envs": [
{ "name": "MyEnv", "hostnames": [{"hostname": "github.io", "ip": [1,2,3,4], "ttl": 55}] }
Expand All @@ -65,8 +60,7 @@ func TestPostHostname(t *testing.T) {

defer local.ResetConf()

ctx := logging.NewContext()
local.LoadConfiguration(ctx)
local.LoadConfiguration()

err := utils.WriteToFile(`{ "remoteDnsServers": [], "envs": [{ "name": "MyOtherEnv" }]}`, utils.GetPath(*flags.ConfPath))

Expand Down Expand Up @@ -110,10 +104,7 @@ func TestPostHostnameInvalidPayloadError(t *testing.T) {
func TestPutHostname(t *testing.T) {

defer local.ResetConf()

ctx := logging.NewContext()
local.LoadConfiguration(ctx)

local.LoadConfiguration()
err := utils.WriteToFile(`{ "remoteDnsServers": [], "envs": [
{ "name": "MyEnv", "hostnames": [{"id": 999, "hostname": "github.io", "ip": [1,2,3,4], "ttl": 55}] }
]}`, utils.GetPath(*flags.ConfPath))
Expand Down Expand Up @@ -145,8 +136,7 @@ func TestDeleteHostname(t *testing.T) {

defer local.ResetConf()

ctx := logging.NewContext()
local.LoadConfiguration(ctx)
local.LoadConfiguration()

err := utils.WriteToFile(`{ "remoteDnsServers": [], "envs": [
{ "name": "MyEnv", "hostnames": [{"hostname": "github.io", "ip": [1,2,3,4], "ttl": 55}] }
Expand Down
23 changes: 11 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2'
services:

# Base Image to build project
gocompiler-docker-dns-proxy:
compiler-dps:
image: golang:1.9
container_name: docker-dns-gocompiler
working_dir: /app/src/github.com/mageddo/dns-proxy-server
Expand All @@ -18,9 +18,8 @@ services:
hostname: dns-proxy-server.dev
network_mode: bridge


# Run from docker image
prod-docker-dns-prod-server:
prod-dps:
container_name: dns-proxy-server
image: defreitas/dns-proxy-server:2.4.1
hostname: dns.mageddo
Expand All @@ -32,24 +31,24 @@ services:
- 5380:5380
network_mode: bridge

# Build project and generate docker image
prod-build-docker-dns-proy-server:
# Build the project and generate binary at build folder
prod-build-binary-dps:
extends: compiler-dps
container_name: docker-dns-server-compiler
command: bash -c "builder build"

# Build project and generate docker image you will need to run prod-build-image-dps first
prod-build-image-dps:
build:
context: .
dockerfile: Dockerfile
container_name: docker-dns-server-docker-compiler
image: defreitas/dns-proxy-server:2.4.1

# Build the project and generate binary at build folder
prod-build-dns-proxy-server:
extends: gocompiler-docker-dns-proxy
container_name: docker-dns-server-compiler
command: bash -c "builder build"

# build the project and make the github release
prod-ci-deploy:
container_name: prod-ci-deploy
extends: gocompiler-docker-dns-proxy
extends: compiler-dps
command: bash -c "builder deploy-ci"
environment:
- CURRENT_BRANCH=$TRAVIS_BRANCH # current branch name
Expand Down
4 changes: 2 additions & 2 deletions docs/Compiling-the-project-from-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Docker-Dns-proxy uses docker to simplify the compile process

Generate the binaries

$ docker-compose up prod-build-dns-proxy-server
$ docker-compose up prod-build-binary-dps
Starting docker-dns-server-compiler
Attaching to docker-dns-server-compiler
docker-dns-server-compiler | ok github.com/mageddo/dns-proxy-server/conf 0.008s
Expand All @@ -18,7 +18,7 @@ Generate the binaries

Create the docker image

$ docker-compose build prod-build-docker-dns-proy-server
$ docker-compose build prod-build-image-dps

# Used tecnologies

Expand Down
2 changes: 1 addition & 1 deletion docs/Developing-at-the-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Setup the environment

$ docker-compose -d gocompiler-docker-dns-proxy up
$ docker-compose -d compiler-dps up
$ docker exec -it gocompiler bash

Running the application
Expand Down
8 changes: 3 additions & 5 deletions events/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package local

import (
"testing"
"github.com/mageddo/go-logging"
"github.com/stretchr/testify/assert"
"github.com/mageddo/dns-proxy-server/cache/store"
)
Expand All @@ -13,15 +12,14 @@ func TestSaveConfiguration_ClearCacheAfterChangeConfiguration(t *testing.T) {

expectedHostname := "github.io"

ctx := logging.NewContext()
conf, err := LoadConfiguration(ctx)
conf, err := LoadConfiguration()
assert.Nil(t, err, "could not load conf")

cache := store.GetInstance()

env, _ := conf.GetActiveEnv()
foundHostname, _ := env.GetHostname(expectedHostname)
assert.Nil(t, foundHostname)
assert.Nil(t, foundHostname, "can't be nil")

// setting the host
cache.Put(expectedHostname, foundHostname)
Expand All @@ -30,7 +28,7 @@ func TestSaveConfiguration_ClearCacheAfterChangeConfiguration(t *testing.T) {

// changing value for the hostname at configuration database
hostname := HostnameVo{Ip: [4]byte{192,168,0,2}, Ttl:30, Env:"", Hostname: expectedHostname}
conf.AddHostname(ctx, "", hostname)
conf.AddHostname( "", hostname)

// cache must be clear after add a hostname in conf
assert.False(t, cache.ContainsKey(expectedHostname))
Expand Down
6 changes: 3 additions & 3 deletions proxy/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestLocalDnsSolver_Solve(t *testing.T) {

defer local.ResetConf()

conf, err := local.LoadConfiguration(ctx)
conf, err := local.LoadConfiguration()
assert.Nil(t, err, "failed to load configuration")

expectedHostname := "github.com"
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestLocalDnsSolver_SolveValidatingCache(t *testing.T) {

defer local.ResetConf()

conf, err := local.LoadConfiguration(ctx)
conf, err := local.LoadConfiguration()
assert.Nil(t, err, "failed to load configuration")

// configuring a new host at local configuration
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestLocalDnsSolver_SolveCacheExpiration(t *testing.T) {

defer local.ResetConf()

conf, err := local.LoadConfiguration(ctx)
conf, err := local.LoadConfiguration()
assert.Nil(t, err, "failed to load configuration")

// configuring a new host at local configuration
Expand Down

0 comments on commit d1807b3

Please sign in to comment.