Skip to content

Commit

Permalink
tests: Fix tests for address methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed May 13, 2020
1 parent 33a1bf8 commit d34286c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
65 changes: 63 additions & 2 deletions dkron/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestEncrypt(t *testing.T) {
a.Stop()
}

func Test_getRPCAddr(t *testing.T) {
func Test_advertiseRPCAddr(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)
Expand All @@ -277,7 +277,68 @@ func Test_getRPCAddr(t *testing.T) {

time.Sleep(2 * time.Second)

getRPCAddr := a.getRPCAddr()
advertiseRPCAddr := a.advertiseRPCAddr()
exRPCAddr := a1Addr + ":6868"

assert.Equal(t, exRPCAddr, advertiseRPCAddr)

a.Stop()

ip2, returnFn2 := testutil.TakeIP()
defer returnFn2()
a2Addr := ip2.String()

c = DefaultConfig()
c.BindAddr = a2Addr + ":5000"
c.AdvertiseAddr = "8.8.8.8"
c.NodeName = "test1"
c.Server = true
c.Tags = map[string]string{"role": "test"}
c.LogLevel = logLevel
c.DevMode = true
c.DataDir = dir

a = NewAgent(c)
a.Start()

time.Sleep(2 * time.Second)

advertiseRPCAddr = a.advertiseRPCAddr()
exRPCAddr = "8.8.8.8:6868"

assert.Equal(t, exRPCAddr, advertiseRPCAddr)

c.AdvertiseAddr = "8.8.8.8"

assert.Equal(t, exRPCAddr, advertiseRPCAddr)

a.Stop()
}

func Test_bindRPCAddr(t *testing.T) {
dir, err := ioutil.TempDir("", "dkron-test")
require.NoError(t, err)
defer os.RemoveAll(dir)

ip1, returnFn1 := testutil.TakeIP()
defer returnFn1()
a1Addr := ip1.String()

c := DefaultConfig()
c.BindAddr = a1Addr + ":5000"
c.NodeName = "test1"
c.Server = true
c.Tags = map[string]string{"role": "test"}
c.LogLevel = logLevel
c.DevMode = true
c.DataDir = dir

a := NewAgent(c)
a.Start()

time.Sleep(2 * time.Second)

getRPCAddr := a.bindRPCAddr()
exRPCAddr := a1Addr + ":6868"

assert.Equal(t, exRPCAddr, getRPCAddr)
Expand Down
4 changes: 2 additions & 2 deletions dkron/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestGRPCExecutionDone(t *testing.T) {
}

rc := NewGRPCClient(nil, a)
rc.ExecutionDone(a.getRPCAddr(), testExecution)
rc.ExecutionDone(a.advertiseRPCAddr(), testExecution)
execs, err := a.Store.GetExecutions("test")
require.NoError(t, err)

Expand All @@ -100,7 +100,7 @@ func TestGRPCExecutionDone(t *testing.T) {

// Test store execution on a deleted job
testExecution.FinishedAt = time.Now()
err = rc.ExecutionDone(a.getRPCAddr(), testExecution)
err = rc.ExecutionDone(a.advertiseRPCAddr(), testExecution)

assert.Error(t, err, ErrExecutionDoneForDeletedJob)
}

0 comments on commit d34286c

Please sign in to comment.