github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/systemd/generate/common_test.go (about)

     1  package generate
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestFilterPodFlags(t *testing.T) {
    11  
    12  	tests := []struct {
    13  		input []string
    14  	}{
    15  		{[]string{"podman", "pod", "create"}},
    16  		{[]string{"podman", "pod", "create", "--name", "foo"}},
    17  		{[]string{"podman", "pod", "create", "--pod-id-file", "foo"}},
    18  		{[]string{"podman", "pod", "create", "--pod-id-file=foo"}},
    19  		{[]string{"podman", "run", "--pod", "foo"}},
    20  		{[]string{"podman", "run", "--pod=foo"}},
    21  	}
    22  
    23  	for _, test := range tests {
    24  		processed := filterPodFlags(test.input)
    25  		for _, s := range processed {
    26  			assert.False(t, strings.HasPrefix(s, "--pod-id-file"))
    27  			assert.False(t, strings.HasPrefix(s, "--pod"))
    28  		}
    29  	}
    30  }
    31  
    32  func TestQuoteArguments(t *testing.T) {
    33  	tests := []struct {
    34  		input  []string
    35  		output []string
    36  	}{
    37  		{
    38  			[]string{"foo", "bar=\"arg\""},
    39  			[]string{"foo", "bar=\"arg\""},
    40  		},
    41  		{
    42  			[]string{"foo", "bar=\"arg with space\""},
    43  			[]string{"foo", "\"bar=\\\"arg with space\\\"\""},
    44  		},
    45  		{
    46  			[]string{"foo", "bar=\"arg with\ttab\""},
    47  			[]string{"foo", "\"bar=\\\"arg with\\ttab\\\"\""},
    48  		},
    49  	}
    50  
    51  	for _, test := range tests {
    52  		quoted := quoteArguments(test.input)
    53  		assert.Equal(t, test.output, quoted)
    54  	}
    55  }