snapshot of https://github.com/grpc/grpc-go.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / vet-proto (push) Failing after 1s
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
Stale bot / stale (push) Failing after 0s
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / vet-proto (push) Failing after 1s
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
Stale bot / stale (push) Failing after 0s
This commit is contained in:
103
internal/xds/xdsclient/xdsresource/name_test.go
Normal file
103
internal/xds/xdsclient/xdsresource/name_test.go
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2021 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package xdsresource
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
)
|
||||
|
||||
func TestParseName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in string
|
||||
want *Name
|
||||
wantStr string
|
||||
}{
|
||||
{
|
||||
name: "old style name",
|
||||
in: "test-resource",
|
||||
want: &Name{ID: "test-resource"},
|
||||
wantStr: "test-resource",
|
||||
},
|
||||
{
|
||||
name: "invalid not url",
|
||||
in: "a:/b/c",
|
||||
want: &Name{ID: "a:/b/c"},
|
||||
wantStr: "a:/b/c",
|
||||
},
|
||||
{
|
||||
name: "invalid no resource type",
|
||||
in: "xdstp://auth/id",
|
||||
want: &Name{ID: "xdstp://auth/id"},
|
||||
wantStr: "xdstp://auth/id",
|
||||
},
|
||||
{
|
||||
name: "valid with no authority",
|
||||
in: "xdstp:///type/id",
|
||||
want: &Name{Scheme: "xdstp", Authority: "", Type: "type", ID: "id"},
|
||||
wantStr: "xdstp:///type/id",
|
||||
},
|
||||
{
|
||||
name: "valid no ctx params",
|
||||
in: "xdstp://auth/type/id",
|
||||
want: &Name{Scheme: "xdstp", Authority: "auth", Type: "type", ID: "id"},
|
||||
wantStr: "xdstp://auth/type/id",
|
||||
},
|
||||
{
|
||||
name: "valid with ctx params",
|
||||
in: "xdstp://auth/type/id?a=1&b=2",
|
||||
want: &Name{Scheme: "xdstp", Authority: "auth", Type: "type", ID: "id", ContextParams: map[string]string{"a": "1", "b": "2"}},
|
||||
wantStr: "xdstp://auth/type/id?a=1&b=2",
|
||||
},
|
||||
{
|
||||
name: "valid with ctx params sorted by keys",
|
||||
in: "xdstp://auth/type/id?b=2&a=1",
|
||||
want: &Name{Scheme: "xdstp", Authority: "auth", Type: "type", ID: "id", ContextParams: map[string]string{"a": "1", "b": "2"}},
|
||||
wantStr: "xdstp://auth/type/id?a=1&b=2",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := ParseName(tt.in)
|
||||
if !cmp.Equal(got, tt.want, cmpopts.IgnoreFields(Name{}, "processingDirective")) {
|
||||
t.Errorf("ParseName() = %#v, want %#v", got, tt.want)
|
||||
}
|
||||
if gotStr := got.String(); gotStr != tt.wantStr {
|
||||
t.Errorf("Name.String() = %s, want %s", gotStr, tt.wantStr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestNameStringCtxParamsOrder covers the case that if two names differ only in
|
||||
// context parameter __order__, the parsed name.String() has the same value.
|
||||
func TestNameStringCtxParamsOrder(t *testing.T) {
|
||||
const (
|
||||
a = "xdstp://auth/type/id?a=1&b=2"
|
||||
b = "xdstp://auth/type/id?b=2&a=1"
|
||||
)
|
||||
aParsed := ParseName(a).String()
|
||||
bParsed := ParseName(b).String()
|
||||
|
||||
if aParsed != bParsed {
|
||||
t.Fatalf("aParsed.String() = %q, bParsed.String() = %q, want them to be the same", aParsed, bParsed)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user