1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
package api
import (
"testing"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/testing/testhelpers"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/pkg/agentcfg"
)
func TestValidation_Valid(t *testing.T) {
tests := []testhelpers.ValidTestcase{
{
Name: "empty Configuration",
Valid: &Configuration{},
},
{
Name: "minimal1 Configuration",
Valid: &Configuration{
DefaultNamespace: "def",
},
},
{
Name: "minimal2 Configuration",
Valid: &Configuration{
DefaultNamespace: "def",
AccessAs: &agentcfg.CiAccessAsCF{
As: &agentcfg.CiAccessAsCF_Agent{
Agent: &agentcfg.CiAccessAsAgentCF{},
},
},
},
},
{
Name: "minimal AllowedAgent",
Valid: &AllowedAgent{
ConfigProject: &ConfigProject{},
},
},
{
Name: "minimal ConfigProject",
Valid: &ConfigProject{},
},
{
Name: "minimal Pipeline",
Valid: &Pipeline{},
},
{
Name: "minimal Project",
Valid: &Project{},
},
{
Name: "Project with groups",
Valid: &Project{
Groups: []*Group{
{},
},
},
},
{
Name: "minimal Group",
Valid: &Group{},
},
{
Name: "minimal Job",
Valid: &Job{},
},
{
Name: "minimal User",
Valid: &User{
Username: "user",
},
},
{
Name: "minimal Environment",
Valid: &Environment{
Slug: "prod",
Tier: "production",
},
},
{
Name: "minimal AllowedAgentsForJob",
Valid: &AllowedAgentsForJob{
Job: &Job{},
Pipeline: &Pipeline{},
Project: &Project{},
User: &User{
Username: "user",
},
},
},
}
testhelpers.AssertValid(t, tests)
}
func TestValidation_Invalid(t *testing.T) {
tests := []testhelpers.InvalidTestcase{
{
ErrString: "invalid AllowedAgent.ConfigProject: value is required",
Invalid: &AllowedAgent{},
},
{
ErrString: "invalid User.Username: value length must be at least 1 bytes",
Invalid: &User{},
},
{
ErrString: "invalid Environment.Slug: value length must be at least 1 bytes; invalid Environment.Tier: value length must be at least 1 bytes",
Invalid: &Environment{},
},
{
ErrString: "invalid AllowedAgentsForJob.Job: value is required; invalid AllowedAgentsForJob.Pipeline: value is required; invalid AllowedAgentsForJob.Project: value is required; invalid AllowedAgentsForJob.User: value is required",
Invalid: &AllowedAgentsForJob{},
},
}
testhelpers.AssertInvalid(t, tests)
}
|