github.com/crowdsecurity/crowdsec@v1.6.1/pkg/csplugin/utils_windows_test.go (about)

     1  //go:build windows
     2  
     3  package csplugin
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  
    10  	"github.com/crowdsecurity/go-cs-lib/cstest"
    11  )
    12  
    13  func TestGetPluginNameAndTypeFromPath(t *testing.T) {
    14  	tests := []struct {
    15  		name        string
    16  		path        string
    17  		want        string
    18  		want1       string
    19  		expectedErr string
    20  	}{
    21  		{
    22  			name:  "valid plugin name, single dash",
    23  			path:  "c:\\path\\to\\notification-gitter",
    24  			want:  "notification",
    25  			want1: "gitter",
    26  		},
    27  		{
    28  			name:        "invalid plugin name",
    29  			path:        "c:\\path\\to\\gitter.exe",
    30  			expectedErr: "plugin name c:\\path\\to\\gitter.exe is invalid. Name should be like {type-name}",
    31  		},
    32  		{
    33  			name:  "valid plugin name, multiple dash",
    34  			path:  "c:\\path\\to\\notification-instant-slack.exe",
    35  			want:  "notification-instant",
    36  			want1: "slack",
    37  		},
    38  	}
    39  	for _, tc := range tests {
    40  		tc := tc
    41  		t.Run(tc.name, func(t *testing.T) {
    42  			got, got1, err := getPluginTypeAndSubtypeFromPath(tc.path)
    43  			cstest.RequireErrorContains(t, err, tc.expectedErr)
    44  
    45  			assert.Equal(t, tc.want, got)
    46  			assert.Equal(t, tc.want1, got1)
    47  		})
    48  	}
    49  }