-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
184 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package admitter | ||
|
||
import "github.com/f1bonacc1/process-compose/src/types" | ||
|
||
type Admitter interface { | ||
Admit(config *types.ProcessConfig) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package admitter | ||
|
||
import "github.com/f1bonacc1/process-compose/src/types" | ||
|
||
type DisabledProcAdmitter struct { | ||
} | ||
|
||
func (d *DisabledProcAdmitter) Admit(proc *types.ProcessConfig) bool { | ||
return !proc.Disabled | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package admitter | ||
|
||
import "github.com/f1bonacc1/process-compose/src/types" | ||
|
||
type NamespaceAdmitter struct { | ||
EnabledNamespaces []string | ||
} | ||
|
||
func (n *NamespaceAdmitter) Admit(proc *types.ProcessConfig) bool { | ||
if len(n.EnabledNamespaces) == 0 { | ||
return true | ||
} | ||
for _, ns := range n.EnabledNamespaces { | ||
if ns == proc.Namespace { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package admitter | ||
|
||
import ( | ||
"github.com/f1bonacc1/process-compose/src/types" | ||
"testing" | ||
) | ||
|
||
func TestNamespaceAdmitter_Admit(t *testing.T) { | ||
type fields struct { | ||
EnabledNamespaces []string | ||
} | ||
type args struct { | ||
proc *types.ProcessConfig | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "no namespace", | ||
fields: fields{ | ||
EnabledNamespaces: []string{}, | ||
}, | ||
args: args{ | ||
proc: &types.ProcessConfig{ | ||
Namespace: "", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "nil namespace", | ||
fields: fields{ | ||
EnabledNamespaces: nil, | ||
}, | ||
args: args{ | ||
proc: &types.ProcessConfig{ | ||
Namespace: "", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "mismatched namespace", | ||
fields: fields{ | ||
EnabledNamespaces: []string{"test"}, | ||
}, | ||
args: args{ | ||
proc: &types.ProcessConfig{ | ||
Namespace: "not-test", | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "matched namespace", | ||
fields: fields{ | ||
EnabledNamespaces: []string{"test"}, | ||
}, | ||
args: args{ | ||
proc: &types.ProcessConfig{ | ||
Namespace: "test", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "matched namespaces", | ||
fields: fields{ | ||
EnabledNamespaces: []string{"not-test", "test"}, | ||
}, | ||
args: args{ | ||
proc: &types.ProcessConfig{ | ||
Namespace: "test", | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
n := &NamespaceAdmitter{ | ||
EnabledNamespaces: tt.fields.EnabledNamespaces, | ||
} | ||
if got := n.Admit(tt.args.proc); got != tt.want { | ||
t.Errorf("Admit() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters