|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package cmd |
| 5 | + |
| 6 | +import ( |
| 7 | + "path/filepath" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | +) |
| 12 | + |
| 13 | +func TestName(t *testing.T) { |
| 14 | + for _, test := range []struct { |
| 15 | + modulePath, moduleRoot, pkgPath, want string |
| 16 | + }{ |
| 17 | + { |
| 18 | + modulePath: "test_package_name", |
| 19 | + moduleRoot: "testdata/test_package_name/test_package_name@v1.0.0", |
| 20 | + want: "test_package_name", |
| 21 | + }, |
| 22 | + { |
| 23 | + modulePath: "test_package_name", |
| 24 | + moduleRoot: "testdata/test_package_name/test_package_name@v1.0.0", |
| 25 | + pkgPath: "subpackage", |
| 26 | + want: "test_package_name/subpackage", |
| 27 | + }, |
| 28 | + { |
| 29 | + modulePath: "test_subpackage", |
| 30 | + moduleRoot: "testdata/test_subpackage", |
| 31 | + want: "test_subpackage", |
| 32 | + }, |
| 33 | + { |
| 34 | + modulePath: "test_subpackage", |
| 35 | + moduleRoot: "testdata/test_subpackage", |
| 36 | + pkgPath: "subpackage", |
| 37 | + want: "test_subpackage/subpackage", |
| 38 | + }, |
| 39 | + } { |
| 40 | + t.Run("", func(t *testing.T) { |
| 41 | + d, err := filepath.Abs(test.moduleRoot) |
| 42 | + require.NoError(t, err) |
| 43 | + p, err := NewPkg(filepath.Join(d, test.pkgPath), test.modulePath, d) |
| 44 | + require.NoError(t, err) |
| 45 | + require.Equal(t, test.want, p.Name()) |
| 46 | + }) |
| 47 | + } |
| 48 | +} |
0 commit comments