11package config
22
33import (
4- "reflect"
54 "strings"
65 "testing"
6+
7+ "github.com/nalgeon/be"
78)
89
910func TestConfig_BoxNames (t * testing.T ) {
@@ -16,9 +17,7 @@ func TestConfig_BoxNames(t *testing.T) {
1617
1718 want := []string {"go" , "python" }
1819 got := cfg .BoxNames ()
19- if ! reflect .DeepEqual (got , want ) {
20- t .Errorf ("BoxNames: expected %v, got %v" , want , got )
21- }
20+ be .Equal (t , got , want )
2221}
2322
2423func TestConfig_CommandNames (t * testing.T ) {
@@ -36,9 +35,7 @@ func TestConfig_CommandNames(t *testing.T) {
3635
3736 want := []string {"go" , "python" }
3837 got := cfg .CommandNames ()
39- if ! reflect .DeepEqual (got , want ) {
40- t .Errorf ("CommandNames: expected %v, got %v" , want , got )
41- }
38+ be .Equal (t , got , want )
4239}
4340
4441func TestConfig_ToJSON (t * testing.T ) {
@@ -60,9 +57,7 @@ func TestConfig_ToJSON(t *testing.T) {
6057 }
6158
6259 got := cfg .ToJSON ()
63- if ! strings .Contains (got , `"pool_size": 8` ) {
64- t .Error ("ToJSON: expected pool_size = 8" )
65- }
60+ be .True (t , strings .Contains (got , `"pool_size": 8` ))
6661}
6762
6863func Test_setBoxDefaults (t * testing.T ) {
@@ -83,45 +78,19 @@ func Test_setBoxDefaults(t *testing.T) {
8378 Files : []string {"config.py" },
8479 }
8580 setBoxDefaults (box , defs )
86- if box .Image != "" {
87- t .Error ("Image: should not set default value" )
88- }
89- if box .Runtime != defs .Runtime {
90- t .Errorf ("Runtime: expected %s, got %s" , defs .Runtime , box .Runtime )
91- }
92- if box .CPU != defs .CPU {
93- t .Errorf ("CPU: expected %d, got %d" , defs .CPU , box .CPU )
94- }
95- if box .Memory != defs .Memory {
96- t .Errorf ("Memory: expected %d, got %d" , defs .Memory , box .Memory )
97- }
98- if box .Storage != defs .Storage {
99- t .Errorf ("Storage: expected %s, got %s" , defs .Storage , box .Storage )
100- }
101- if box .Network != defs .Network {
102- t .Errorf ("Network: expected %s, got %s" , defs .Network , box .Network )
103- }
104- if box .Volume != defs .Volume {
105- t .Errorf ("Volume: expected %s, got %s" , defs .Volume , box .Volume )
106- }
107- if ! reflect .DeepEqual (box .Tmpfs , defs .Tmpfs ) {
108- t .Errorf ("Tmpfs: expected %v, got %v" , defs .Tmpfs , box .Tmpfs )
109- }
110- if ! reflect .DeepEqual (box .CapAdd , defs .CapAdd ) {
111- t .Errorf ("CapAdd: expected %v, got %v" , defs .CapAdd , box .CapAdd )
112- }
113- if ! reflect .DeepEqual (box .CapDrop , defs .CapDrop ) {
114- t .Errorf ("CapDrop: expected %v, got %v" , defs .CapDrop , box .CapDrop )
115- }
116- if ! reflect .DeepEqual (box .Ulimit , defs .Ulimit ) {
117- t .Errorf ("Ulimit: expected %v, got %v" , defs .Ulimit , box .Ulimit )
118- }
119- if box .NProc != defs .NProc {
120- t .Errorf ("NProc: expected %d, got %d" , defs .NProc , box .NProc )
121- }
122- if len (box .Files ) != 0 {
123- t .Error ("Files: should not set default value" )
124- }
81+ be .Equal (t , box .Image , "" )
82+ be .Equal (t , box .Runtime , defs .Runtime )
83+ be .Equal (t , box .CPU , defs .CPU )
84+ be .Equal (t , box .Memory , defs .Memory )
85+ be .Equal (t , box .Storage , defs .Storage )
86+ be .Equal (t , box .Network , defs .Network )
87+ be .Equal (t , box .Volume , defs .Volume )
88+ be .Equal (t , box .Tmpfs , defs .Tmpfs )
89+ be .Equal (t , box .CapAdd , defs .CapAdd )
90+ be .Equal (t , box .CapDrop , defs .CapDrop )
91+ be .Equal (t , box .Ulimit , defs .Ulimit )
92+ be .Equal (t , box .NProc , defs .NProc )
93+ be .Equal (t , len (box .Files ), 0 )
12594}
12695
12796func Test_setStepDefaults (t * testing.T ) {
@@ -136,22 +105,10 @@ func Test_setStepDefaults(t *testing.T) {
136105 }
137106
138107 setStepDefaults (step , defs )
139- if step .Box != "" {
140- t .Error ("Box: should not set default value" )
141- }
142- if step .User != defs .User {
143- t .Errorf ("User: expected %s, got %s" , defs .User , step .User )
144- }
145- if step .Action != defs .Action {
146- t .Errorf ("Action: expected %s, got %s" , defs .Action , step .Action )
147- }
148- if len (step .Command ) != 0 {
149- t .Error ("Command: should not set default value" )
150- }
151- if step .Timeout != defs .Timeout {
152- t .Errorf ("Timeout: expected %d, got %d" , defs .Timeout , step .Timeout )
153- }
154- if step .NOutput != defs .NOutput {
155- t .Errorf ("NOutput: expected %d, got %d" , defs .NOutput , step .NOutput )
156- }
108+ be .Equal (t , step .Box , "" )
109+ be .Equal (t , step .User , defs .User )
110+ be .Equal (t , step .Action , defs .Action )
111+ be .Equal (t , len (step .Command ), 0 )
112+ be .Equal (t , step .Timeout , defs .Timeout )
113+ be .Equal (t , step .NOutput , defs .NOutput )
157114}
0 commit comments