github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/plugins_response_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestPluginsResponseJson(t *testing.T) {
    14  	manifest := &Manifest{
    15  		Id: "theid",
    16  		Server: &ManifestServer{
    17  			Executable: "theexecutable",
    18  		},
    19  		Webapp: &ManifestWebapp{
    20  			BundlePath: "thebundlepath",
    21  		},
    22  	}
    23  
    24  	response := &PluginsResponse{
    25  		Active:   []*PluginInfo{{Manifest: *manifest}},
    26  		Inactive: []*PluginInfo{},
    27  	}
    28  
    29  	json := response.ToJson()
    30  	newResponse := PluginsResponseFromJson(strings.NewReader(json))
    31  	assert.Equal(t, newResponse, response)
    32  	assert.Equal(t, newResponse.ToJson(), json)
    33  	assert.Equal(t, PluginsResponseFromJson(strings.NewReader("junk")), (*PluginsResponse)(nil))
    34  }