From c8cff3a97a34ae7aab65330abb12267d003b237d Mon Sep 17 00:00:00 2001 From: Artur Shellunts Date: Mon, 6 Feb 2023 10:25:21 +0100 Subject: [PATCH] Rename TestPairSearch and refactor it 1. Extract test setup code so that it is visible what exactly is tested. 2. Removed check of checklist because that is tested by call to getBestAvailableCandidatePair. 3. Use require.* instead of assert.* 4. Removed check for leaked routines and timer. Because the test is super simple. --- ..._get_best_available_candidate_pair_test.go | 28 +++++++++++++ agent_pair_search_test.go | 39 ------------------- 2 files changed, 28 insertions(+), 39 deletions(-) create mode 100644 agent_get_best_available_candidate_pair_test.go delete mode 100644 agent_pair_search_test.go diff --git a/agent_get_best_available_candidate_pair_test.go b/agent_get_best_available_candidate_pair_test.go new file mode 100644 index 0000000..5077ba3 --- /dev/null +++ b/agent_get_best_available_candidate_pair_test.go @@ -0,0 +1,28 @@ +//go:build !js +// +build !js + +package ice + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNoBestAvailableCandidatePairAfterAgentConstruction(t *testing.T) { + agent := setupTest(t) + + require.Nil(t, agent.getBestAvailableCandidatePair()) + + tearDownTest(t, agent) +} + +func setupTest(t *testing.T) *Agent { + agent, err := NewAgent(&AgentConfig{}) + require.NoError(t, err) + return agent +} + +func tearDownTest(t *testing.T, agent *Agent) { + require.NoError(t, agent.Close()) +} diff --git a/agent_pair_search_test.go b/agent_pair_search_test.go deleted file mode 100644 index 30b53b7..0000000 --- a/agent_pair_search_test.go +++ /dev/null @@ -1,39 +0,0 @@ -//go:build !js -// +build !js - -package ice - -import ( - "testing" - "time" - - "github.com/pion/transport/test" - "github.com/stretchr/testify/assert" -) - -func TestPairSearch(t *testing.T) { - report := test.CheckRoutines(t) - defer report() - - // Limit runtime in case of deadlocks - lim := test.TimeOut(time.Second * 10) - defer lim.Stop() - - var config AgentConfig - a, err := NewAgent(&config) - if err != nil { - t.Fatalf("Error constructing ice.Agent") - } - - if len(a.checklist) != 0 { - t.Fatalf("TestPairSearch is only a valid test if a.validPairs is empty on construction") - } - - cp := a.getBestAvailableCandidatePair() - - if cp != nil { - t.Fatalf("No Candidate pairs should exist") - } - - assert.NoError(t, a.Close()) -}