Skip to content

Commit c80753c

Browse files
committed
Add unit test tags
1 parent a6239f8 commit c80753c

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

ecs-agent/daemonimages/csidriver/util/utils_test.go renamed to ecs-agent/daemonimages/csidriver/util/utils_linux_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build linux && unit
2+
// +build linux,unit
3+
14
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
25
//
36
// Licensed under the Apache License, Version 2.0 (the "License"). You may
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//go:build windows && unit
2+
// +build windows,unit
3+
4+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
7+
// not use this file except in compliance with the License. A copy of the
8+
// License is located at
9+
//
10+
// http://aws.amazon.com/apache2.0/
11+
//
12+
// or in the "license" file accompanying this file. This file is distributed
13+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
// express or implied. See the License for the specific language governing
15+
// permissions and limitations under the License.
16+
17+
package util
18+
19+
import (
20+
"fmt"
21+
"testing"
22+
23+
"github.com/stretchr/testify/assert"
24+
)
25+
26+
func TestParseEndpoint(t *testing.T) {
27+
testCases := []struct {
28+
name string
29+
endpoint string
30+
expScheme string
31+
expAddr string
32+
expErr error
33+
}{
34+
{
35+
name: "valid unix endpoint 1",
36+
endpoint: "unix:\\csi\\csi.sock",
37+
expScheme: "unix",
38+
expAddr: "/csi/csi.sock",
39+
},
40+
{
41+
name: "invalid endpoint",
42+
endpoint: "http://127.0.0.1",
43+
expErr: fmt.Errorf("unsupported protocol: http"),
44+
},
45+
}
46+
47+
for _, tc := range testCases {
48+
t.Run(tc.name, func(t *testing.T) {
49+
scheme, addr, err := ParseEndpoint(tc.endpoint)
50+
51+
if tc.expErr != nil {
52+
assert.EqualError(t, err, tc.expErr.Error())
53+
} else {
54+
assert.Nil(t, err)
55+
assert.Equal(t, scheme, tc.expScheme, "scheme mismatches")
56+
assert.Equal(t, addr, tc.expAddr, "address mismatches")
57+
}
58+
})
59+
}
60+
61+
}

0 commit comments

Comments
 (0)