Skip to content

Commit

Permalink
service: improve tests by avoiding making assertions inside goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz committed Oct 3, 2018
1 parent 172ac0e commit e0b6dc6
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,9 @@ func TestNew(t *testing.T) {
archive, err := xarchive.GzippedTar(path)
require.NoError(t, err)

statuses := make(chan DeployStatus)
statuses := make(chan DeployStatus, 4)
var wg sync.WaitGroup

wg.Add(1)
go func() {
defer wg.Done()

require.Equal(t, DeployStatus{
Message: "Receiving service context...",
Type: DRunning,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: "Service context received with success",
Type: DDonePositive,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: "Building Docker image...",
Type: DRunning,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: "Image built with success",
Type: DDonePositive,
}, <-statuses)
}()

s, err := New(archive,
ContainerOption(mc),
DeployStatusOption(statuses),
Expand All @@ -104,6 +79,26 @@ func TestNew(t *testing.T) {
require.Equal(t, "service", s.Dependencies[0].Key)
require.Equal(t, hash, s.Dependencies[0].Image)

require.Equal(t, DeployStatus{
Message: "Receiving service context...",
Type: DRunning,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: "Service context received with success",
Type: DDonePositive,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: "Building Docker image...",
Type: DRunning,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: "Image built with success",
Type: DDonePositive,
}, <-statuses)

mc.AssertExpectations(t)
wg.Wait()
}
Expand Down

0 comments on commit e0b6dc6

Please sign in to comment.