Skip to content

Commit d8f6960

Browse files
committed
Merge branch 'feat/gcs-file-provider' of https://github.com/Suryakantdsa/gofr into feat/gcs-file-provider
2 parents b9ebe29 + e230f80 commit d8f6960

File tree

38 files changed

+3272
-536
lines changed

38 files changed

+3272
-536
lines changed

.github/workflows/go.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
command: |
103103
export APP_ENV=test
104104
# Run tests for the examples directory with coverage
105-
go test gofr.dev/examples/... -v -short -coverprofile packageWithpbgo.cov -coverpkg=gofr.dev/examples/...
105+
go test ./examples/... -v -short -covermode=atomic -coverprofile packageWithpbgo.cov -coverpkg=./examples/...
106106
# Filter out auto-generated files by protobuf and gofr framework from coverage report
107107
grep -vE '(/client/|grpc-.+-client/main\.go|_client\.go|_gofr\.go|_grpc\.pb\.go|\.pb\.go|\.proto|health_.*\.go)' packageWithpbgo.cov > profile.cov
108108
# Display coverage statistics
@@ -211,8 +211,8 @@ jobs:
211211
- name: Merge Coverage Files
212212
working-directory: artifacts
213213
run: |
214-
awk '!/^mode: / && FNR==1{print "mode: set"} {print}' ./Example-Test-Report/profile.cov > merged_profile.cov
215-
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
214+
echo "mode: atomic" > merged_profile.cov
215+
grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
216216
217217
# Calculate and output the total code coverage percentage
218218
- name: Parse code-coverage value
@@ -222,6 +222,7 @@ jobs:
222222
codeCoverage=${codeCoverage%?}
223223
echo "CODE_COVERAGE=$codeCoverage" >> $GITHUB_ENV
224224
echo "✅ Total Code Coverage: $codeCoverage%"
225+
225226
# - name: Check if code-coverage is greater than threshold
226227
# run: |
227228
# codeCoverage=${{ env.CODE_COVERAGE }}
@@ -332,9 +333,8 @@ jobs:
332333
- name: Merge Coverage Files
333334
working-directory: artifacts
334335
run: |
335-
echo "mode: set" > merged_profile.cov
336-
tail -n +2 ./Example-Test-Report/profile.cov >> merged_profile.cov
337-
tail -n +2 ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
336+
echo "mode: atomic" > merged_profile.cov
337+
grep -h -v "mode:" ./Example-Test-Report/profile.cov ./PKG-Coverage-Report/profile.cov >> merged_profile.cov
338338
339339
# Generate and print total coverage percentage
340340
echo "Total Coverage:"

.github/workflows/typos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
- name: Checkout Code
1212
uses: actions/checkout@v5
1313
- name: typos-action
14-
uses: crate-ci/[email protected].0
14+
uses: crate-ci/[email protected].1

docs/navigation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const navigation = [
1010

1111
{
1212
title: 'CLI Applications',
13-
href: '/docs/cli/cli',
13+
href: '/docs/quick-start/cli',
1414
desc: "Learn to build powerful command-line interface (CLI) applications using GoFr's app.NewCMD(), offering a robust framework for command-line tools."
1515
},
1616

docs/cli/cli.md renamed to docs/quick-start/cli/page.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
GoFr provides a simple way to build command-line applications using `app.NewCMD()`. This creates standalone CLI tools without starting an HTTP server.
44

5+
## Configuration
6+
To configure logging for CLI applications, set the following environment variable:
7+
- `CMD_LOGS_FILE`: The file path where CLI logs will be written. If not set, logs are discarded.
8+
9+
510
## Getting Started
611

712
Create a basic CLI application with subcommands:
@@ -71,4 +76,4 @@ go build -o mycli
7176
./mycli --help
7277
```
7378

74-
For more details, see the [sample-cmd example](../../examples/sample-cmd).
79+
For more details, see the [sample-cmd example](../../../examples/sample-cmd).
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package client
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
"google.golang.org/grpc"
9+
"google.golang.org/grpc/credentials/insecure"
10+
healthpb "google.golang.org/grpc/health/grpc_health_v1"
11+
12+
"gofr.dev/pkg/gofr"
13+
"gofr.dev/pkg/gofr/testutil"
14+
)
15+
16+
func TestGoFrHealthClientWrapper_Creation(t *testing.T) {
17+
t.Setenv("GOFR_TELEMETRY", "false")
18+
19+
configs := testutil.NewServerConfigs(t)
20+
21+
t.Run("NewHealthClient", func(t *testing.T) {
22+
// Test GoFr's NewHealthClient function
23+
conn, err := grpc.Dial(configs.GRPCHost, grpc.WithTransportCredentials(insecure.NewCredentials()))
24+
require.NoError(t, err, "Connection creation should not fail immediately")
25+
defer conn.Close()
26+
27+
healthClient := NewHealthClient(conn)
28+
assert.NotNil(t, healthClient, "GoFr health client should not be nil")
29+
30+
// Test that it implements the GoFr interface
31+
var _ HealthClient = healthClient
32+
})
33+
34+
t.Run("HealthClientWrapperInterface", func(t *testing.T) {
35+
// Test GoFr's interface compliance
36+
conn, err := grpc.Dial(configs.GRPCHost, grpc.WithTransportCredentials(insecure.NewCredentials()))
37+
require.NoError(t, err, "Connection creation should not fail immediately")
38+
defer conn.Close()
39+
40+
healthClient := NewHealthClient(conn)
41+
42+
// Test HealthClient interface compliance
43+
var _ HealthClient = healthClient
44+
45+
// Test that wrapper has the correct GoFr type
46+
wrapper, ok := healthClient.(*HealthClientWrapper)
47+
assert.True(t, ok, "Should be able to cast to GoFr HealthClientWrapper")
48+
assert.NotNil(t, wrapper.client, "Underlying health client should not be nil")
49+
})
50+
}
51+
52+
func TestGoFrHealthClientWrapper_Methods(t *testing.T) {
53+
t.Setenv("GOFR_TELEMETRY", "false")
54+
55+
configs := testutil.NewServerConfigs(t)
56+
57+
// Test GoFr's wrapper methods without actual gRPC calls
58+
conn, err := grpc.Dial(configs.GRPCHost, grpc.WithTransportCredentials(insecure.NewCredentials()))
59+
require.NoError(t, err, "Connection creation should not fail immediately")
60+
defer conn.Close()
61+
62+
healthClient := NewHealthClient(conn)
63+
ctx := createTestContext()
64+
65+
t.Run("CheckMethodExists", func(t *testing.T) {
66+
// Test that GoFr's Check method exists and accepts correct parameters
67+
req := &healthpb.HealthCheckRequest{
68+
Service: "test-service",
69+
}
70+
71+
// This will fail due to connection, but we're testing GoFr's method signature
72+
_, err := healthClient.Check(ctx, req)
73+
assert.Error(t, err, "Should fail with invalid connection, but method should exist")
74+
})
75+
76+
t.Run("WatchMethodExists", func(t *testing.T) {
77+
// Test that GoFr's Watch method exists and accepts correct parameters
78+
req := &healthpb.HealthCheckRequest{
79+
Service: "test-service",
80+
}
81+
82+
// This will fail due to connection, but we're testing GoFr's method signature
83+
_, err := healthClient.Watch(ctx, req)
84+
assert.Error(t, err, "Should fail with invalid connection, but method should exist")
85+
})
86+
}
87+
88+
func TestGoFrHealthClientWrapper_ContextIntegration(t *testing.T) {
89+
t.Setenv("GOFR_TELEMETRY", "false")
90+
91+
configs := testutil.NewServerConfigs(t)
92+
93+
// Test GoFr's context integration
94+
conn, err := grpc.Dial(configs.GRPCHost, grpc.WithTransportCredentials(insecure.NewCredentials()))
95+
require.NoError(t, err, "Connection creation should not fail immediately")
96+
defer conn.Close()
97+
98+
healthClient := NewHealthClient(conn)
99+
100+
t.Run("ContextParameter", func(t *testing.T) {
101+
// Test that GoFr's methods accept *gofr.Context
102+
ctx := createTestContext()
103+
req := &healthpb.HealthCheckRequest{
104+
Service: "test-service",
105+
}
106+
107+
// Test that the method signature is correct for GoFr context
108+
_, err := healthClient.Check(ctx, req)
109+
assert.Error(t, err, "Should fail with invalid connection")
110+
111+
// Test that context is properly passed (even though call fails)
112+
assert.NotNil(t, ctx, "GoFr context should not be nil")
113+
})
114+
115+
t.Run("ContextTypeCompliance", func(t *testing.T) {
116+
// Test that GoFr's methods expect *gofr.Context specifically
117+
ctx := createTestContext()
118+
req := &healthpb.HealthCheckRequest{
119+
Service: "test-service",
120+
}
121+
122+
// Verify the method signature expects *gofr.Context
123+
var _ func(*gofr.Context, *healthpb.HealthCheckRequest, ...grpc.CallOption) (*healthpb.HealthCheckResponse, error) = healthClient.Check
124+
var _ func(*gofr.Context, *healthpb.HealthCheckRequest, ...grpc.CallOption) (grpc.ServerStreamingClient[healthpb.HealthCheckResponse], error) = healthClient.Watch
125+
126+
// Ensure the call compiles (even if it fails at runtime)
127+
_, _ = healthClient.Check(ctx, req)
128+
_, _ = healthClient.Watch(ctx, req)
129+
})
130+
}
131+
132+
func TestGoFrHealthClientWrapper_ErrorHandling(t *testing.T) {
133+
t.Setenv("GOFR_TELEMETRY", "false")
134+
135+
// Test GoFr's error handling patterns
136+
t.Run("InvalidConnectionHandling", func(t *testing.T) {
137+
// Test GoFr's handling of invalid connections
138+
conn, err := grpc.Dial("invalid:address", grpc.WithTransportCredentials(insecure.NewCredentials()))
139+
require.NoError(t, err, "Connection creation should not fail immediately")
140+
defer conn.Close()
141+
142+
healthClient := NewHealthClient(conn)
143+
ctx := createTestContext()
144+
145+
req := &healthpb.HealthCheckRequest{
146+
Service: "test-service",
147+
}
148+
149+
// Test GoFr's error handling
150+
_, err = healthClient.Check(ctx, req)
151+
assert.Error(t, err, "GoFr should handle invalid connection errors")
152+
})
153+
}

0 commit comments

Comments
 (0)