@@ -658,3 +658,71 @@ func Test_cleanActions(t *testing.T) {
658
658
})
659
659
}
660
660
}
661
+
662
+ func Test_getAllScopesForHost (t * testing.T ) {
663
+ host := "registry.example.com"
664
+ tests := []struct {
665
+ name string
666
+ scopes []string
667
+ globalScopes []string
668
+ want []string
669
+ }{
670
+ {
671
+ name : "Empty per-host scopes" ,
672
+ scopes : []string {},
673
+ globalScopes : []string {
674
+ "repository:hello-world:push" ,
675
+ "repository:alpine:delete" ,
676
+ "repository:hello-world:pull" ,
677
+ "repository:alpine:delete" ,
678
+ },
679
+ want : []string {
680
+ "repository:alpine:delete" ,
681
+ "repository:hello-world:pull,push" ,
682
+ },
683
+ },
684
+ {
685
+ name : "Empty global scopes" ,
686
+ scopes : []string {
687
+ "repository:hello-world:push" ,
688
+ "repository:alpine:delete" ,
689
+ "repository:hello-world:pull" ,
690
+ "repository:alpine:delete" ,
691
+ },
692
+ globalScopes : []string {},
693
+ want : []string {
694
+ "repository:alpine:delete" ,
695
+ "repository:hello-world:pull,push" ,
696
+ },
697
+ },
698
+ {
699
+ name : "Per-host scopes + global scopes" ,
700
+ scopes : []string {
701
+ "repository:hello-world:push" ,
702
+ "repository:alpine:delete" ,
703
+ "repository:hello-world:pull" ,
704
+ "repository:alpine:delete" ,
705
+ },
706
+ globalScopes : []string {
707
+ "repository:foo:pull" ,
708
+ "repository:hello-world:pull" ,
709
+ "repository:alpine:pull" ,
710
+ },
711
+ want : []string {
712
+ "repository:alpine:delete,pull" ,
713
+ "repository:foo:pull" ,
714
+ "repository:hello-world:pull,push" ,
715
+ },
716
+ },
717
+ }
718
+ for _ , tt := range tests {
719
+ t .Run (tt .name , func (t * testing.T ) {
720
+ ctx := context .Background ()
721
+ ctx = WithScopesForHost (ctx , host , tt .scopes ... )
722
+ ctx = WithScopes (ctx , tt .globalScopes ... )
723
+ if got := getAllScopesForHost (ctx , host ); ! reflect .DeepEqual (got , tt .want ) {
724
+ t .Errorf ("getAllScopesForHost() = %v, want %v" , got , tt .want )
725
+ }
726
+ })
727
+ }
728
+ }
0 commit comments