fix(cli): preserve integer precision in jq output (#3991)
parent
cefd5920f8
commit
ff33184433
|
|
@ -0,0 +1,32 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
|
||||
"github.com/Tencent/WeKnora/cli/internal/config"
|
||||
"github.com/Tencent/WeKnora/cli/internal/iostreams"
|
||||
sdk "github.com/Tencent/WeKnora/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestStatusJQPreservesTenantID(t *testing.T) {
|
||||
out, _ := iostreams.SetForTest(t)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "/api/v1/auth/me", r.URL.Path)
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"user":{"id":"user-test","tenant_id":9007199254740993}}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
f := &cmdutil.Factory{Config: func() (*config.Config, error) {
|
||||
return &config.Config{CurrentProfile: "test", Profiles: map[string]config.Profile{
|
||||
"test": {Host: server.URL},
|
||||
}}, nil
|
||||
}}
|
||||
require.NoError(t, runStatus(context.Background(),
|
||||
&cmdutil.FormatOptions{Mode: cmdutil.FormatJSON, JQ: ".data.tenant_id"}, f, sdk.NewClient(server.URL)))
|
||||
assert.Equal(t, "9007199254740993\n", out.String())
|
||||
}
|
||||
|
|
@ -69,7 +69,9 @@ func writeJQ(w io.Writer, raw []byte, expr string) error {
|
|||
return &JQError{Err: fmt.Errorf("jq parse: %w", err)}
|
||||
}
|
||||
var input any
|
||||
if err := json.Unmarshal(raw, &input); err != nil {
|
||||
decoder := json.NewDecoder(bytes.NewReader(raw))
|
||||
decoder.UseNumber()
|
||||
if err := decoder.Decode(&input); err != nil {
|
||||
return fmt.Errorf("jq input parse: %w", err)
|
||||
}
|
||||
iter := query.Run(input)
|
||||
|
|
|
|||
Loading…
Reference in New Issue