File: validation.go

package info (click to toggle)
gitlab-agent 16.11.5-1
  • links: PTS, VCS
  • area: contrib
  • in suites: experimental
  • size: 7,072 kB
  • sloc: makefile: 193; sh: 55; ruby: 3
file content (38 lines) | stat: -rw-r--r-- 671 bytes parent folder | download | duplicates (2)
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
package testhelpers

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

type Validatable interface {
	ValidateAll() error
}

type InvalidTestcase struct {
	ErrString string
	Invalid   Validatable
}

type ValidTestcase struct {
	Name  string
	Valid Validatable
}

func AssertInvalid(t *testing.T, tests []InvalidTestcase) {
	for _, tc := range tests {
		t.Run(tc.ErrString, func(t *testing.T) {
			err := tc.Invalid.ValidateAll()
			assert.EqualError(t, err, tc.ErrString)
		})
	}
}

func AssertValid(t *testing.T, tests []ValidTestcase) {
	for _, tc := range tests {
		t.Run(tc.Name, func(t *testing.T) {
			assert.NoError(t, tc.Valid.ValidateAll())
		})
	}
}