File tree 5 files changed +95
-7
lines changed
5 files changed +95
-7
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ import (
27
27
"github.com/matryer/is"
28
28
)
29
29
30
- func TestConfig_WithFlags (t * testing.T ) {
30
+ func TestConfigWithFlags (t * testing.T ) {
31
31
testCases := []struct {
32
32
name string
33
33
args []string
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ package root
17
17
import (
18
18
"context"
19
19
"fmt"
20
- "os"
21
20
22
21
"github.com/conduitio/conduit/cmd/conduit/root/config"
23
22
"github.com/conduitio/conduit/cmd/conduit/root/connectorplugins"
39
38
_ ecdysis.CommandWithExecute = (* RootCommand )(nil )
40
39
_ ecdysis.CommandWithDocs = (* RootCommand )(nil )
41
40
_ ecdysis.CommandWithSubCommands = (* RootCommand )(nil )
41
+ _ ecdysis.CommandWithOutput = (* RootCommand )(nil )
42
42
)
43
43
44
44
type RootFlags struct {
@@ -50,12 +50,17 @@ type RootFlags struct {
50
50
}
51
51
52
52
type RootCommand struct {
53
- flags RootFlags
53
+ flags RootFlags
54
+ output ecdysis.Output
55
+ }
56
+
57
+ func (c * RootCommand ) Output (output ecdysis.Output ) {
58
+ c .output = output
54
59
}
55
60
56
61
func (c * RootCommand ) Execute (ctx context.Context ) error {
57
62
if c .flags .Version {
58
- _ , _ = fmt . Fprintf ( os .Stdout , "%s\n " , conduit .Version (true ))
63
+ c . output .Stdout ( fmt . Sprintf ( "%s\n " , conduit .Version (true ) ))
59
64
return nil
60
65
}
61
66
Original file line number Diff line number Diff line change 15
15
package root
16
16
17
17
import (
18
+ "bytes"
19
+ "context"
20
+ "strings"
18
21
"testing"
19
22
23
+ "github.com/conduitio/conduit/pkg/conduit"
20
24
"github.com/conduitio/ecdysis"
21
25
"github.com/matryer/is"
22
26
"github.com/spf13/pflag"
@@ -56,3 +60,28 @@ func TestRootCommandFlags(t *testing.T) {
56
60
is .Equal (cf .Usage , f .usage )
57
61
}
58
62
}
63
+
64
+ func TestRootCommandExecuteWithVersionFlag (t * testing.T ) {
65
+ is := is .New (t )
66
+
67
+ buf := new (bytes.Buffer )
68
+
69
+ out := & ecdysis.DefaultOutput {}
70
+ out .Output (buf , nil )
71
+
72
+ cmd := & RootCommand {
73
+ flags : RootFlags {
74
+ Version : true ,
75
+ },
76
+ }
77
+ cmd .Output (out )
78
+
79
+ expectedOutput := strings .TrimSpace (conduit .Version (true ))
80
+
81
+ err := cmd .Execute (context .Background ())
82
+ is .NoErr (err )
83
+
84
+ actualOutput := strings .TrimSpace (buf .String ())
85
+
86
+ is .Equal (actualOutput , expectedOutput )
87
+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ package version
17
17
import (
18
18
"context"
19
19
"fmt"
20
- "os"
21
20
22
21
"github.com/conduitio/conduit/pkg/conduit"
23
22
"github.com/conduitio/ecdysis"
@@ -26,14 +25,21 @@ import (
26
25
var (
27
26
_ ecdysis.CommandWithExecute = (* VersionCommand )(nil )
28
27
_ ecdysis.CommandWithDocs = (* VersionCommand )(nil )
28
+ _ ecdysis.CommandWithOutput = (* VersionCommand )(nil )
29
29
)
30
30
31
- type VersionCommand struct {}
31
+ type VersionCommand struct {
32
+ output ecdysis.Output
33
+ }
34
+
35
+ func (c * VersionCommand ) Output (output ecdysis.Output ) {
36
+ c .output = output
37
+ }
32
38
33
39
func (c * VersionCommand ) Usage () string { return "version" }
34
40
35
41
func (c * VersionCommand ) Execute (_ context.Context ) error {
36
- _ , _ = fmt . Fprintf ( os .Stdout , "%s\n " , conduit .Version (true ))
42
+ c . output .Stdout ( fmt . Sprintf ( "%s\n " , conduit .Version (true ) ))
37
43
return nil
38
44
}
39
45
Original file line number Diff line number Diff line change
1
+ // Copyright © 2025 Meroxa, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ package version
16
+
17
+ import (
18
+ "bytes"
19
+ "context"
20
+ "fmt"
21
+ "runtime"
22
+ "strings"
23
+ "testing"
24
+
25
+ "github.com/conduitio/ecdysis"
26
+ "github.com/matryer/is"
27
+ )
28
+
29
+ func TestVersionCommandExecute (t * testing.T ) {
30
+ is := is .New (t )
31
+
32
+ buf := new (bytes.Buffer )
33
+
34
+ out := & ecdysis.DefaultOutput {}
35
+ out .Output (buf , nil )
36
+
37
+ cmd := & VersionCommand {}
38
+ cmd .Output (out )
39
+
40
+ expectedOutput := fmt .Sprintf ("%s/%s" , runtime .GOOS , runtime .GOARCH )
41
+
42
+ err := cmd .Execute (context .Background ())
43
+ is .NoErr (err )
44
+
45
+ actualOutput := strings .TrimSpace (buf .String ())
46
+
47
+ is .Equal (actualOutput , expectedOutput )
48
+ }
You can’t perform that action at this time.
0 commit comments