github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/status/status_test.go (about)

     1  // Copyright 2019 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package status
     5  
     6  import (
     7  	"encoding/json"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/keybase/client/go/libkb"
    12  	jsonw "github.com/keybase/go-jsonw"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  func TestMergeExtendedStatus(t *testing.T) {
    17  	tc := libkb.SetupTest(t, "MergedExtendedStatus", 1)
    18  	defer tc.Cleanup()
    19  	lsCtx := LogSendContext{
    20  		Contextified: libkb.NewContextified(tc.G),
    21  	}
    22  
    23  	// invalid json is skipped
    24  	fullStatus := lsCtx.mergeExtendedStatus("")
    25  	require.Equal(t, fullStatus, "")
    26  
    27  	// Status is merged in under the key 'status'
    28  	status := `{"status":{"foo":"bar"}}`
    29  	fullStatus = lsCtx.mergeExtendedStatus(status)
    30  	require.True(t, strings.Contains(fullStatus, status))
    31  
    32  	err := jsonw.EnsureMaxDepthBytesDefault([]byte(fullStatus))
    33  	require.NoError(t, err)
    34  
    35  	fullStatusMap := map[string]interface{}{}
    36  	err = json.Unmarshal([]byte(fullStatus), &fullStatusMap)
    37  	require.NoError(t, err)
    38  	_, ok := fullStatusMap["status"]
    39  	require.True(t, ok)
    40  }
    41  
    42  func TestFullStatus(t *testing.T) {
    43  	tc := libkb.SetupTest(t, "FullStatus", 1)
    44  	defer tc.Cleanup()
    45  	mctx := libkb.NewMetaContextForTest(tc)
    46  	fstatus, err := GetFullStatus(mctx)
    47  	require.NoError(t, err)
    48  	require.NotNil(t, fstatus)
    49  }