nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: tablelandnetwork/go-tableland
Pull request #587 (2023-06-28 04:51:52)

[got-111] change empty /query status to 200
# Summary

This PR ensures that we don't return 404 from the Gateway API if the table is empty i.e. there are no rows in the table.

# Context

[GOT-111] [JST-28]



# Checklist

- [ ]  Are changes backward compatible with existing SDKs, or is there a plan to manage it correctly?
- [x]  Are changes covered by existing tests, or were new tests included?
- [x]  Are code changes optimized for future code readers, commenting on problematic areas to understand (if any)?
- [x]  Future-self question: Did you avoid unjustified/unnecessary complexity to achieve the goal?



Patch:
diff --git a/internal/router/controllers/controller.go b/internal/router/controllers/controller.go
index 7994da9..073d256 100644
--- a/internal/router/controllers/controller.go
+++ b/internal/router/controllers/controller.go
@@ -282,11 +282,7 @@ func (c *Controller) runReadRequest(
 		_ = json.NewEncoder(rw).Encode(errors.ServiceError{Message: err.Error()})
 		return nil, false
 	}
-	if len(res.Rows) == 0 {
-		rw.WriteHeader(http.StatusNotFound)
-		_ = json.NewEncoder(rw).Encode(errors.ServiceError{Message: "Row not found"})
-		return nil, false
-	}
+
 	return res, true
 }
 


Test patch:
diff --git a/internal/router/controllers/controller_test.go b/internal/router/controllers/controller_test.go
index 9c917ab..1a2cce6 100644
--- a/internal/router/controllers/controller_test.go
+++ b/internal/router/controllers/controller_test.go
@@ -90,6 +90,46 @@ func TestQuery(t *testing.T) {
 	}
 }
 
+func TestQueryEmptyTable(t *testing.T) {
+	r := mocks.NewGateway(t)
+	r.EXPECT().RunReadQuery(mock.Anything, mock.AnythingOfType("string")).Return(
+		&gateway.TableData{
+			Columns: []gateway.Column{
+				{Name: "id"},
+				{Name: "name"},
+			},
+			Rows: [][]*gateway.ColumnValue{},
+		},
+		nil,
+	)
+
+	ctrl := NewController(r)
+
+	router := mux.NewRouter()
+	router.HandleFunc("/query", ctrl.GetTableQuery)
+
+	ctx := context.WithValue(context.Background(), middlewares.ContextIPAddress, strconv.Itoa(1))
+	// Table format
+	req, err := http.NewRequestWithContext(ctx, "GET", "/query?statement=select%20*%20from%20foo%3B&format=table", nil)
+	require.NoError(t, err)
+	rr := httptest.NewRecorder()
+	router.ServeHTTP(rr, req)
+	require.Equal(t, http.StatusOK, rr.Code)
+	exp := `{"columns":[{"name":"id"},{"name":"name"}],"rows":[]}` // nolint
+	require.JSONEq(t, exp, rr.Body.String())
+
+	// Unwrapped object format
+	req, err = http.NewRequest("GET", "/query?statement=select%20*%20from%20foo%3B&format=objects&unwrap=true", nil)
+	require.NoError(t, err)
+	rr = httptest.NewRecorder()
+	router.ServeHTTP(rr, req)
+	require.Equal(t, http.StatusOK, rr.Code)
+	exp = ""
+	wantString := parseJSONLString(exp)
+	gotString := parseJSONLString(rr.Body.String())
+	require.Equal(t, wantString, gotString)
+}
+
 func TestQueryExtracted(t *testing.T) {
 	r := mocks.NewGateway(t)
 	r.EXPECT().RunReadQuery(mock.Anything, mock.AnythingOfType("string")).Return(
Repository: mr-linch/go-tg
Pull request #116 (2023-02-18 01:26:13)

feat(tg): add link helpers to Username


Patch:
diff --git a/examples/run.go b/examples/run.go
index 85d99c5..da3c506 100644
--- a/examples/run.go
+++ b/examples/run.go
@@ -64,7 +64,7 @@ func run(ctx context.Context, handler tgb.Handler) error {
 		return fmt.Errorf("get me: %w", err)
 	}
 
-	log.Printf("authorized as https://t.me/%s", me.Username)
+	log.Printf("authorized as %s", me.Username.Link())
 
 	if flagWebhookURL != "" {
 		err = tgb.NewWebhook(
diff --git a/types_gen_ext.go b/types_gen_ext.go
index 466cbb4..e55c94e 100644
--- a/types_gen_ext.go
+++ b/types_gen_ext.go
@@ -114,10 +114,21 @@ func (id UserID) PeerID() string {
 // Username represents a Telegram username.
 type Username string
 
+// PeerID implements [Peer] interface.
 func (un Username) PeerID() string {
 	return "@" + string(un)
 }
 
+// Link returns a public link with username.
+func (un Username) Link() string {
+	return "https://t.me/" + string(un)
+}
+
+// DeepLink returns a deep link with username.
+func (un Username) DeepLink() string {
+	return "tg://resolve?domain=" + string(un)
+}
+
 // PeerID represents generic Telegram peer.
 //
 // Known implementations:


Test patch:
diff --git a/types_gen_ext_test.go b/types_gen_ext_test.go
index 0267bde..d49bee5 100644
--- a/types_gen_ext_test.go
+++ b/types_gen_ext_test.go
@@ -26,6 +26,14 @@ func TestUsername_PeerID(t *testing.T) {
 	assert.Equal(t, "@username", Username("username").PeerID())
 }
 
+func TestUsername_Link(t *testing.T) {
+	assert.Equal(t, "https://t.me/username", Username("username").Link())
+}
+
+func TestUsername_DeepLink(t *testing.T) {
+	assert.Equal(t, "tg://resolve?domain=username", Username("username").DeepLink())
+}
+
 func TestChatType_String(t *testing.T) {
 	for _, test := range []struct {
 		ChatType ChatType