...

Source file src/google.golang.org/api/google-api-go-generator/replacements_test.go

Documentation: google.golang.org/api/google-api-go-generator

     1  // Copyright 2020 Google LLC.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import "testing"
     8  
     9  func TestDeprecatedPkgs(t *testing.T) {
    10  	tests := []struct {
    11  		name      string
    12  		dp        deprecatedPkgs
    13  		inName    string
    14  		inVersion string
    15  		want      string
    16  	}{
    17  		{
    18  			name:      "replacement found",
    19  			dp:        deprecatedPkgs{"foo:v1": "example.com/foo"},
    20  			inName:    "foo",
    21  			inVersion: "v1",
    22  			want:      "example.com/foo",
    23  		},
    24  		{
    25  			name:      "replacemet found with no versions specified",
    26  			dp:        deprecatedPkgs{"foo": "example.com/foo"},
    27  			inName:    "foo",
    28  			inVersion: "v1",
    29  			want:      "example.com/foo",
    30  		},
    31  		{
    32  			name:      "no replacement found, package not in map",
    33  			dp:        deprecatedPkgs{"foo": "example.com/foo"},
    34  			inName:    "bar",
    35  			inVersion: "v1",
    36  			want:      "",
    37  		},
    38  		{
    39  			name:      "no replacement found, version mismatch",
    40  			dp:        deprecatedPkgs{"foo:v1": "example.com/foo"},
    41  			inName:    "foo",
    42  			inVersion: "v2",
    43  			want:      "",
    44  		},
    45  	}
    46  	for _, tc := range tests {
    47  		t.Run(tc.name, func(t *testing.T) {
    48  			got := tc.dp.Get(tc.inName, tc.inVersion)
    49  			if got != tc.want {
    50  				t.Errorf("deprecatedPkg.Get(%v, %v): got %q, want %q", tc.inName, tc.inVersion, got, tc.want)
    51  			}
    52  		})
    53  	}
    54  }
    55  

View as plain text