@@ -2,13 +2,15 @@ package cli
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"testing"
6
7
8
+ "github.com/DefangLabs/defang/src/pkg/cli/client"
7
9
"github.com/DefangLabs/defang/src/pkg/cli/compose"
8
10
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
9
11
)
10
12
11
- func TestDebug (t * testing.T ) {
13
+ func TestFindMathingProjectFiles (t * testing.T ) {
12
14
project , err := compose .NewLoader (compose .WithPath ("../../tests/debugproj/compose.yaml" )).LoadProject (context .Background ())
13
15
if err != nil {
14
16
t .Fatal (err )
@@ -33,3 +35,47 @@ func TestDebug(t *testing.T) {
33
35
}
34
36
}
35
37
}
38
+
39
+ type MustHaveProjectNameQueryProvider struct {
40
+ client.Provider
41
+ }
42
+
43
+ func (m MustHaveProjectNameQueryProvider ) Query (ctx context.Context , req * defangv1.DebugRequest ) error {
44
+ if req .Project == "" {
45
+ return errors .New ("project name is missing" )
46
+ }
47
+ return nil
48
+ }
49
+
50
+ type MockDebugFabricClient struct {
51
+ client.FabricClient
52
+ }
53
+
54
+ func (m MockDebugFabricClient ) Debug (ctx context.Context , req * defangv1.DebugRequest ) (* defangv1.DebugResponse , error ) {
55
+ return & defangv1.DebugResponse {}, nil
56
+ }
57
+
58
+ func TestQueryHasProject (t * testing.T ) {
59
+ project , err := compose .NewLoader (compose .WithPath ("../../tests/debugproj/compose.yaml" )).LoadProject (context .Background ())
60
+ if err != nil {
61
+ t .Fatal (err )
62
+ }
63
+
64
+ provider := MustHaveProjectNameQueryProvider {}
65
+ fabricClient := MockDebugFabricClient {}
66
+
67
+ if err := Debug (context .Background (), compose .NewLoader (), fabricClient , provider , "etag" , project , []string {"service" }); err != nil {
68
+ t .Errorf ("expected no error, got %v" , err )
69
+ }
70
+
71
+ project .Name = ""
72
+
73
+ if err := Debug (context .Background (), compose .NewLoader (), fabricClient , provider , "etag" , project , []string {"service" }); err == nil {
74
+ t .Error ("expected error, got nil" )
75
+ } else {
76
+ if err .Error () != "project name is missing" {
77
+ t .Errorf ("expected error %q, got %q" , "project name is missing" , err .Error ())
78
+ }
79
+ }
80
+
81
+ }
0 commit comments