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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
package agentcfg
import (
"testing"
"time"
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/testing/testhelpers"
"google.golang.org/protobuf/types/known/durationpb"
)
func TestValidation_Valid(t *testing.T) {
tests := []testhelpers.ValidTestcase{
{
Name: "empty",
Valid: &AgentConfiguration{},
},
{
Name: "empty CiAccessGroupCF.DefaultNamespace",
Valid: &CiAccessGroupCF{
Id: "abc",
DefaultNamespace: "", // empty is ok
},
},
{
Name: "empty environments CiAccessGroupCF.Environments",
Valid: &CiAccessGroupCF{
Id: "abc",
Environments: []string{},
},
},
{
Name: "multiple environments CiAccessGroupCF.Environments",
Valid: &CiAccessGroupCF{
Id: "abc",
Environments: []string{"a", "b"},
},
},
{
Name: "empty environments CiAccessProjectCF.Environments",
Valid: &CiAccessProjectCF{
Id: "abc",
Environments: []string{},
},
},
{
Name: "multiple environments CiAccessProjectCF.Environments",
Valid: &CiAccessProjectCF{
Id: "abc",
Environments: []string{"a", "b"},
},
},
{
Name: "empty CiAccessAsAgentCF",
Valid: &CiAccessAsAgentCF{},
},
{
Name: "empty CiAccessAsCiJobCF",
Valid: &CiAccessAsCiJobCF{},
},
{
Name: "minimal CiAccessAsImpersonateCF",
Valid: &CiAccessAsImpersonateCF{
Username: "abc",
},
},
{
Name: "one group CiAccessAsImpersonateCF",
Valid: &CiAccessAsImpersonateCF{
Username: "abc",
Groups: []string{"g"},
},
},
{
Name: "ManifestProjectCF with no Id",
Valid: &ManifestProjectCF{},
},
{
Name: "minimal ChartValuesUrlCF",
Valid: &ChartValuesUrlCF{
Url: "https://example.com",
},
},
{
Name: "minimal RemoteCF",
Valid: &RemoteCF{},
},
{
Name: "RemoteCF with valid intervals",
Valid: &RemoteCF{
PartialSyncInterval: durationpb.New(1 * time.Second),
FullSyncInterval: durationpb.New(1 * time.Second),
},
},
}
testhelpers.AssertValid(t, tests)
}
func TestValidation_Invalid(t *testing.T) {
emptyId := ""
tests := []testhelpers.InvalidTestcase{
{
ErrString: "invalid ManifestProjectCF.Id: value length must be at least 1 bytes",
Invalid: &ManifestProjectCF{
Id: &emptyId, // empty id is not ok
},
},
{
ErrString: "invalid PathCF.Glob: value length must be at least 1 bytes",
Invalid: &PathCF{
Glob: emptyId,
},
},
{
ErrString: "invalid CiAccessGroupCF.Id: value length must be at least 1 bytes",
Invalid: &CiAccessGroupCF{
Id: emptyId, // empty id is not ok
},
},
{
ErrString: "invalid CiAccessGroupCF.Environments[0]: value length must be at least 1 bytes",
Invalid: &CiAccessGroupCF{
Id: "abc",
Environments: []string{""},
},
},
{
ErrString: "invalid CiAccessProjectCF.Environments[0]: value length must be at least 1 bytes",
Invalid: &CiAccessProjectCF{
Id: "abc",
Environments: []string{""},
},
},
{
ErrString: "invalid CiAccessAsCF.As: value is required",
Invalid: &CiAccessAsCF{},
},
{
ErrString: "invalid CiAccessAsCF.Agent: value is required",
Invalid: &CiAccessAsCF{
As: &CiAccessAsCF_Agent{},
},
},
{
ErrString: "invalid CiAccessAsCF.Impersonate: value is required",
Invalid: &CiAccessAsCF{
As: &CiAccessAsCF_Impersonate{},
},
},
{
ErrString: "invalid CiAccessAsCF.CiJob: value is required",
Invalid: &CiAccessAsCF{
As: &CiAccessAsCF_CiJob{},
},
},
{
ErrString: "invalid CiAccessAsImpersonateCF.Username: value length must be at least 1 bytes",
Invalid: &CiAccessAsImpersonateCF{},
},
{
ErrString: "invalid CiAccessAsImpersonateCF.Groups[0]: value length must be at least 1 bytes",
Invalid: &CiAccessAsImpersonateCF{
Username: "a",
Groups: []string{""},
},
},
{
ErrString: "invalid ExtraKeyValCF.Key: value length must be at least 1 bytes; invalid ExtraKeyValCF.Val: value must contain at least 1 item(s)",
Invalid: &ExtraKeyValCF{},
},
{
ErrString: "invalid ChartValuesCF.From: value is required",
Invalid: &ChartValuesCF{},
},
{
ErrString: "invalid ChartValuesUrlCF.Url: value must be absolute",
Invalid: &ChartValuesUrlCF{},
},
{
ErrString: "invalid RemoteCF.PartialSyncInterval: value must be greater than 0s; invalid RemoteCF.FullSyncInterval: value must be greater than 0s",
Invalid: &RemoteCF{
PartialSyncInterval: durationpb.New(0),
FullSyncInterval: durationpb.New(0),
},
},
}
testhelpers.AssertInvalid(t, tests)
}
|