(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestGetTokenScopes(t *testing.T) { |
| 60 | testCases := []struct { |
| 61 | scopesInCtx []string |
| 62 | commonScopes []string |
| 63 | expected []string |
| 64 | }{ |
| 65 | { |
| 66 | scopesInCtx: []string{}, |
| 67 | commonScopes: []string{}, |
| 68 | expected: []string{}, |
| 69 | }, |
| 70 | { |
| 71 | scopesInCtx: []string{}, |
| 72 | commonScopes: []string{"repository:foo/bar:pull"}, |
| 73 | expected: []string{"repository:foo/bar:pull"}, |
| 74 | }, |
| 75 | { |
| 76 | scopesInCtx: []string{"repository:foo/bar:pull,push"}, |
| 77 | commonScopes: []string{}, |
| 78 | expected: []string{"repository:foo/bar:pull,push"}, |
| 79 | }, |
| 80 | { |
| 81 | scopesInCtx: []string{"repository:foo/bar:pull"}, |
| 82 | commonScopes: []string{"repository:foo/bar:pull"}, |
| 83 | expected: []string{"repository:foo/bar:pull"}, |
| 84 | }, |
| 85 | { |
| 86 | scopesInCtx: []string{"repository:foo/bar:pull"}, |
| 87 | commonScopes: []string{"repository:foo/bar:pull,push"}, |
| 88 | expected: []string{"repository:foo/bar:pull", "repository:foo/bar:pull,push"}, |
| 89 | }, |
| 90 | { |
| 91 | scopesInCtx: []string{"repository:foo/bar:pull"}, |
| 92 | commonScopes: []string{"repository:foo/bar:pull,push", "repository:foo/bar:pull"}, |
| 93 | expected: []string{"repository:foo/bar:pull", "repository:foo/bar:pull,push"}, |
| 94 | }, |
| 95 | } |
| 96 | for _, tc := range testCases { |
| 97 | ctx := context.WithValue(context.TODO(), tokenScopesKey{}, tc.scopesInCtx) |
| 98 | actual := GetTokenScopes(ctx, tc.commonScopes) |
| 99 | assert.Equal(t, tc.expected, actual) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func TestCustomScope(t *testing.T) { |
| 104 | scope := "whatever:foo/bar:pull" |
nothing calls this directly
no test coverage detected
searching dependent graphs…