github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/app/plugin_api_tests/test_get_bundle_path_plugin/main.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"path/filepath"
     9  
    10  	"github.com/mattermost/mattermost-server/v5/app/plugin_api_tests"
    11  	"github.com/mattermost/mattermost-server/v5/model"
    12  	"github.com/mattermost/mattermost-server/v5/plugin"
    13  )
    14  
    15  type MyPlugin struct {
    16  	plugin.MattermostPlugin
    17  	configuration plugin_api_tests.BasicConfig
    18  }
    19  
    20  func (p *MyPlugin) OnConfigurationChange() error {
    21  	if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
    22  		return err
    23  	}
    24  	return nil
    25  }
    26  
    27  func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
    28  	bundlePath, err := p.API.GetBundlePath()
    29  	if err != nil {
    30  		return nil, err.Error() + "failed get bundle path"
    31  	} else if bundlePathFromConfig, _ := filepath.Abs(filepath.Join(*p.API.GetConfig().PluginSettings.Directory, "test_get_bundle_path_plugin")); bundlePathFromConfig != bundlePath {
    32  		return nil, fmt.Sprintf("Invalid bundle path returned: %v vs %v", bundlePathFromConfig, bundlePath)
    33  	}
    34  
    35  	return nil, "OK"
    36  }
    37  
    38  func main() {
    39  	plugin.ClientMain(&MyPlugin{})
    40  }