@@ -139,10 +139,10 @@ func TestSpacemeshApp_AddLogger(t *testing.T) {
139
139
myLogger := "anton"
140
140
subLogger := app .addLogger (myLogger , lg )
141
141
subLogger .Debug ("should not get printed" )
142
- teststr := "should get printed"
143
- subLogger .Info (teststr )
142
+ testStr := "should get printed"
143
+ subLogger .Info (testStr )
144
144
r .Equal (
145
- fmt .Sprintf ("INFO\t %s\t %s\n " , myLogger , teststr ),
145
+ fmt .Sprintf ("INFO\t %s\t %s\n " , myLogger , testStr ),
146
146
buf .String (),
147
147
)
148
148
}
@@ -339,8 +339,8 @@ func (f *noopHook) OnWrite(*zapcore.CheckedEntry, []zapcore.Field) {}
339
339
// E2E app test of the stream endpoints in the NodeService.
340
340
func TestSpacemeshApp_NodeService (t * testing.T ) {
341
341
logger := logtest .New (t )
342
- // errlog is used to simulate errors in the app
343
- errlog := log .NewFromLog (
342
+ // errLog is used to simulate errors in the app
343
+ errLog := log .NewFromLog (
344
344
zaptest .NewLogger (t , zaptest .WrapOptions (zap .Hooks (events .EventHook ()), zap .WithPanicHook (& noopHook {}))),
345
345
)
346
346
@@ -430,9 +430,9 @@ func TestSpacemeshApp_NodeService(t *testing.T) {
430
430
431
431
// Report two errors and make sure they're both received
432
432
eg .Go (func () error {
433
- errlog .Error ("test123" )
434
- errlog .Error ("test456" )
435
- errlog .Panic ("testPANIC" )
433
+ errLog .Error ("test123" )
434
+ errLog .Error ("test456" )
435
+ errLog .Panic ("testPANIC" )
436
436
return nil
437
437
})
438
438
@@ -602,7 +602,7 @@ func TestConfig_Preset(t *testing.T) {
602
602
require .NoError (t , err )
603
603
604
604
conf := config.Config {}
605
- require .NoError (t , loadConfig (& conf , name , "" ))
605
+ require .NoError (t , LoadConfig (& conf , name , nil ))
606
606
require .Equal (t , preset , conf )
607
607
})
608
608
@@ -615,7 +615,7 @@ func TestConfig_Preset(t *testing.T) {
615
615
cmd .AddFlags (& flags , & conf )
616
616
617
617
const lowPeers = 1234
618
- require .NoError (t , loadConfig (& conf , name , "" ))
618
+ require .NoError (t , LoadConfig (& conf , name , nil ))
619
619
require .NoError (t , flags .Parse ([]string {"--low-peers=" + strconv .Itoa (lowPeers )}))
620
620
preset .P2P .LowPeers = lowPeers
621
621
require .Equal (t , preset , conf )
@@ -628,10 +628,8 @@ func TestConfig_Preset(t *testing.T) {
628
628
conf := config.Config {}
629
629
const lowPeers = 1234
630
630
content := fmt .Sprintf (`{"p2p": {"low-peers": %d}}` , lowPeers )
631
- path := filepath .Join (t .TempDir (), "config.json" )
632
- require .NoError (t , os .WriteFile (path , []byte (content ), 0o600 ))
633
631
634
- require .NoError (t , loadConfig (& conf , name , path ))
632
+ require .NoError (t , LoadConfig (& conf , name , strings . NewReader ( content ) ))
635
633
preset .P2P .LowPeers = lowPeers
636
634
require .Equal (t , preset , conf )
637
635
})
@@ -642,10 +640,8 @@ func TestConfig_Preset(t *testing.T) {
642
640
643
641
conf := config.Config {}
644
642
content := fmt .Sprintf (`{"preset": "%s"}` , name )
645
- path := filepath .Join (t .TempDir (), "config.json" )
646
- require .NoError (t , os .WriteFile (path , []byte (content ), 0o600 ))
647
643
648
- require .NoError (t , loadConfig (& conf , name , path ))
644
+ require .NoError (t , LoadConfig (& conf , name , strings . NewReader ( content ) ))
649
645
require .NoError (t , err )
650
646
require .Equal (t , preset , conf )
651
647
})
@@ -719,7 +715,7 @@ func TestConfig_CustomTypes(t *testing.T) {
719
715
var flags pflag.FlagSet
720
716
cmd .AddFlags (& flags , & conf )
721
717
722
- require .NoError (t , loadConfig (& conf , "" , "" ))
718
+ require .NoError (t , LoadConfig (& conf , "" , nil ))
723
719
require .NoError (t , flags .Parse (strings .Fields (tc .cli )))
724
720
tc .updatePreset (t , & mainnet )
725
721
require .Equal (t , mainnet , conf )
@@ -730,10 +726,8 @@ func TestConfig_CustomTypes(t *testing.T) {
730
726
require .Nil (t , mainnet .SMESHING .Opts .ProviderID .Value ())
731
727
732
728
conf := config .MainnetConfig ()
733
- path := filepath .Join (t .TempDir (), "config.json" )
734
- require .NoError (t , os .WriteFile (path , []byte (tc .config ), 0o600 ))
735
729
736
- require .NoError (t , loadConfig (& conf , "" , path ))
730
+ require .NoError (t , LoadConfig (& conf , "" , strings . NewReader ( tc . config ) ))
737
731
tc .updatePreset (t , & mainnet )
738
732
require .Equal (t , mainnet , conf )
739
733
})
@@ -746,7 +740,7 @@ func TestConfig_CustomTypes(t *testing.T) {
746
740
var flags pflag.FlagSet
747
741
cmd .AddFlags (& flags , & conf )
748
742
749
- require .NoError (t , loadConfig (& conf , name , "" ))
743
+ require .NoError (t , LoadConfig (& conf , name , nil ))
750
744
require .NoError (t , flags .Parse (strings .Fields (tc .cli )))
751
745
tc .updatePreset (t , & preset )
752
746
require .Equal (t , preset , conf )
@@ -757,10 +751,8 @@ func TestConfig_CustomTypes(t *testing.T) {
757
751
require .NoError (t , err )
758
752
759
753
conf := config.Config {}
760
- path := filepath .Join (t .TempDir (), "config.json" )
761
- require .NoError (t , os .WriteFile (path , []byte (tc .config ), 0o600 ))
762
754
763
- require .NoError (t , loadConfig (& conf , name , path ))
755
+ require .NoError (t , LoadConfig (& conf , name , strings . NewReader ( tc . config ) ))
764
756
tc .updatePreset (t , & preset )
765
757
require .Equal (t , preset , conf )
766
758
})
@@ -803,10 +795,8 @@ func TestConfig_PostProviderID_InvalidValues(t *testing.T) {
803
795
t .Run (fmt .Sprintf ("%s_ConfigFile" , tc .name ), func (t * testing.T ) {
804
796
conf := config.Config {}
805
797
806
- path := filepath .Join (t .TempDir (), "config.json" )
807
798
cfg := fmt .Sprintf (`{"smeshing": {"smeshing-opts": {"smeshing-opts-provider": %s}}}` , tc .configValue )
808
- require .NoError (t , os .WriteFile (path , []byte (cfg ), 0o600 ))
809
- err := loadConfig (& conf , "" , path )
799
+ err := LoadConfig (& conf , "" , strings .NewReader (cfg ))
810
800
require .ErrorContains (t , err , "invalid provider ID value" )
811
801
})
812
802
}
@@ -816,18 +806,15 @@ func TestConfig_Load(t *testing.T) {
816
806
t .Run ("invalid fails to load" , func (t * testing.T ) {
817
807
conf := config.Config {}
818
808
819
- path := filepath .Join (t .TempDir (), "config.json" )
820
- require .NoError (t , os .WriteFile (path , []byte ("}" ), 0o600 ))
821
-
822
- err := loadConfig (& conf , "" , path )
823
- require .ErrorContains (t , err , path )
809
+ err := LoadConfig (& conf , "" , strings .NewReader ("}" ))
810
+ require .ErrorContains (t , err , "invalid character '}' looking for beginning of value" )
824
811
})
825
812
t .Run ("missing default doesn't fail" , func (t * testing.T ) {
826
813
conf := config.Config {}
827
814
var flags pflag.FlagSet
828
815
cmd .AddFlags (& flags , & conf )
829
816
830
- require .NoError (t , loadConfig (& conf , "" , "" ))
817
+ require .NoError (t , LoadConfig (& conf , "" , nil ))
831
818
require .NoError (t , flags .Parse ([]string {}))
832
819
})
833
820
}
@@ -848,7 +835,7 @@ func TestConfig_GenesisAccounts(t *testing.T) {
848
835
args = append (args , fmt .Sprintf ("-a %s=%d" , key , value ))
849
836
}
850
837
851
- require .NoError (t , loadConfig (& conf , "" , "" ))
838
+ require .NoError (t , LoadConfig (& conf , "" , nil ))
852
839
require .NoError (t , flags .Parse (args ))
853
840
for _ , key := range keys {
854
841
require .EqualValues (t , value , conf .Genesis .Accounts [key ])
@@ -858,9 +845,7 @@ func TestConfig_GenesisAccounts(t *testing.T) {
858
845
func TestHRP (t * testing.T ) {
859
846
conf := config.Config {}
860
847
data := `{"main": {"network-hrp": "TEST"}}`
861
- cfg := filepath .Join (t .TempDir (), "config.json" )
862
- require .NoError (t , os .WriteFile (cfg , []byte (data ), 0o600 ))
863
- require .NoError (t , loadConfig (& conf , "" , cfg ))
848
+ require .NoError (t , LoadConfig (& conf , "" , strings .NewReader (data )))
864
849
app := New (WithConfig (& conf ))
865
850
require .NotNil (t , app )
866
851
require .Equal (t , "TEST" , types .NetworkHRP ())
0 commit comments