@@ -8,14 +8,13 @@ import (
88 "github.com/UpCloudLtd/upcloud-cli/v3/internal/config"
99 smock "github.com/UpCloudLtd/upcloud-cli/v3/internal/mock"
1010
11- "github.com/gemalto/flume"
1211 "github.com/stretchr/testify/assert"
1312)
1413
1514func TestExecutor_WaitFor (t * testing.T ) {
1615 mService := & smock.Service {}
1716 cfg := config .New ()
18- exec := NewExecutor (cfg , mService , flume . New ("test" ))
17+ exec := NewExecutor (cfg , mService , cfg . NewLogger ("test" ))
1918 finished := false
2019 // normal operation
2120 go func () {
@@ -34,7 +33,7 @@ func TestExecutor_WaitFor(t *testing.T) {
3433func TestExecutor_WaitForTimeout (t * testing.T ) {
3534 mService := & smock.Service {}
3635 cfg := config .New ()
37- exec := NewExecutor (cfg , mService , flume . New ("test" ))
36+ exec := NewExecutor (cfg , mService , cfg . NewLogger ("test" ))
3837 err := exec .WaitFor (func () error {
3938 time .Sleep (50 * time .Minute )
4039 return nil
@@ -45,74 +44,10 @@ func TestExecutor_WaitForTimeout(t *testing.T) {
4544func TestExecutor_WaitForError (t * testing.T ) {
4645 mService := & smock.Service {}
4746 cfg := config .New ()
48- exec := NewExecutor (cfg , mService , flume . New ("test" ))
47+ exec := NewExecutor (cfg , mService , cfg . NewLogger ("test" ))
4948 err := exec .WaitFor (func () error {
5049 time .Sleep (10 * time .Millisecond )
5150 return fmt .Errorf ("mockmock" )
5251 }, 100 * time .Millisecond )
5352 assert .EqualError (t , err , "mockmock" )
5453}
55-
56- type mockLogEntry struct {
57- Msg string
58- Args []any
59- }
60-
61- type mockLogger struct {
62- debugLines []mockLogEntry
63- infoLines []mockLogEntry
64- errorLines []mockLogEntry
65- context []any
66- }
67-
68- func (m * mockLogger ) Debug (msg string , args ... any ) {
69- m .debugLines = append (m .debugLines , mockLogEntry {msg , args })
70- }
71-
72- func (m * mockLogger ) Info (msg string , args ... any ) {
73- m .infoLines = append (m .infoLines , mockLogEntry {msg , args })
74- }
75-
76- func (m * mockLogger ) Error (msg string , args ... any ) {
77- m .errorLines = append (m .errorLines , mockLogEntry {msg , args })
78- }
79-
80- func (m mockLogger ) IsDebug () bool {
81- return true
82- }
83-
84- func (m mockLogger ) IsInfo () bool {
85- return true
86- }
87-
88- func (m mockLogger ) With (args ... any ) flume.Logger {
89- return & mockLogger {
90- context : append (m .context , args ... ),
91- }
92- }
93-
94- func TestExecutor_Logging (t * testing.T ) {
95- mService := & smock.Service {}
96- cfg := config .New ()
97- logger := & mockLogger {context : []any {"base" , "context" }}
98- exec := NewExecutor (cfg , mService , logger )
99- exec .Debug ("debug1" , "hello" , "world" )
100- // create a contexted executor
101- contextExec := exec .WithLogger ("added" , "newcontext" )
102- contextExec .Debug ("debugcontext" , "helloz" , "worldz" )
103- exec .Debug ("debug2" , "hi" , "earth" )
104- // make sure the main executor does not leak to the contexted one or vice versa
105- assert .Equal (t , & mockLogger {
106- debugLines : []mockLogEntry {
107- {Msg : "debug1" , Args : []any {"hello" , "world" }},
108- {Msg : "debug2" , Args : []any {"hi" , "earth" }},
109- },
110- context : []any {"base" , "context" },
111- }, logger )
112- assert .Equal (t , & mockLogger {
113- debugLines : []mockLogEntry {
114- {Msg : "debugcontext" , Args : []any {"helloz" , "worldz" }},
115- },
116- context : []any {"base" , "context" , "added" , "newcontext" },
117- }, contextExec .(* executorImpl ).logger )
118- }
0 commit comments