...

Source file src/github.com/redhat-developer/odo/pkg/dev/common/attributes_test.go

Documentation: github.com/redhat-developer/odo/pkg/dev/common

     1  package common
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
     7  	"github.com/devfile/api/v2/pkg/attributes"
     8  	"github.com/google/go-cmp/cmp"
     9  )
    10  
    11  func TestGetSyncFilesFromAttributes(t *testing.T) {
    12  	type args struct {
    13  		command v1alpha2.Command
    14  	}
    15  	tests := []struct {
    16  		name string
    17  		args args
    18  		want map[string]string
    19  	}{
    20  		{
    21  			name: "no attributes",
    22  			args: args{
    23  				command: v1alpha2.Command{},
    24  			},
    25  			want: make(map[string]string),
    26  		},
    27  		{
    28  			name: "no matching attributes",
    29  			args: args{
    30  				command: v1alpha2.Command{
    31  					Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
    32  						"some-custom-attribute-key":    "some-value",
    33  						"another-custom-attribute-key": "some-value",
    34  					}),
    35  				},
    36  			},
    37  			want: make(map[string]string),
    38  		},
    39  		{
    40  			name: "dev.odo.push.path attribute key",
    41  			args: args{
    42  				command: v1alpha2.Command{
    43  					Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
    44  						"dev.odo.push.path": "some-value",
    45  					}),
    46  				},
    47  			},
    48  			want: make(map[string]string),
    49  		},
    50  		{
    51  			name: "attribute with only matching prefix as key",
    52  			args: args{
    53  				command: v1alpha2.Command{
    54  					Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
    55  						_devPushPathAttributePrefix: "server/",
    56  					}),
    57  				},
    58  			},
    59  			want: map[string]string{
    60  				".": "server",
    61  			},
    62  		},
    63  		{
    64  			name: "multiple matching attributes",
    65  			args: args{
    66  				command: v1alpha2.Command{
    67  					Attributes: attributes.Attributes{}.FromStringMap(map[string]string{
    68  						"some-custom-attribute-key":                      "some-value",
    69  						_devPushPathAttributePrefix + "server.js":        "server/server.js",
    70  						"some-other-custom-attribute-key":                "some-value",
    71  						_devPushPathAttributePrefix + "some-path/README": "another/nested/path/README.md",
    72  						_devPushPathAttributePrefix + "random-file.txt":  "/tmp/rand-file.txt",
    73  					}),
    74  				},
    75  			},
    76  			want: map[string]string{
    77  				"server.js":        "server/server.js",
    78  				"some-path/README": "another/nested/path/README.md",
    79  				"random-file.txt":  "/tmp/rand-file.txt",
    80  			},
    81  		},
    82  	}
    83  	for _, tt := range tests {
    84  		t.Run(tt.name, func(t *testing.T) {
    85  			got := GetSyncFilesFromAttributes(tt.args.command)
    86  			if diff := cmp.Diff(tt.want, got); diff != "" {
    87  				t.Errorf("GetSyncFilesFromAttributes() mismatch (-want +got):\n%s", diff)
    88  			}
    89  		})
    90  	}
    91  }
    92  

View as plain text