53007a9257
Compile a host's catalog in a base and a test environment over the puppetserver API, then diff the two. - add catalog-diff CLI with cobra flags, config precedence and exit codes - add puppetserver mTLS client for POST /puppet/v4/catalog - add pdbmux fact client - add catalog normalisation, diff engine and text/JSON renderers - add Makefile, nfpm RPM packaging and woodpecker pipelines
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package catalog
|
|
|
|
import "testing"
|
|
|
|
func TestBranchToEnvironment(t *testing.T) {
|
|
tests := []struct {
|
|
branch string
|
|
want string
|
|
}{
|
|
{"develop", "develop"},
|
|
{"benvin/foo-bar", "benvin_foo_bar"},
|
|
{"benvin/scaffold-catalog-diff", "benvin_scaffold_catalog_diff"},
|
|
{"feature/PUP-1234", "feature_PUP_1234"},
|
|
{"release/1.2.3", "release_1_2_3"},
|
|
{"already_ok_123", "already_ok_123"},
|
|
{"dots.and spaces", "dots_and_spaces"},
|
|
{"trailing/", "trailing_"},
|
|
{"", ""},
|
|
{"UPPER", "UPPER"},
|
|
{"héllo", "h_llo"},
|
|
}
|
|
for _, tc := range tests {
|
|
if got := BranchToEnvironment(tc.branch); got != tc.want {
|
|
t.Errorf("BranchToEnvironment(%q) = %q, want %q", tc.branch, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidEnvironmentName(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
want bool
|
|
}{
|
|
{"develop", true},
|
|
{"benvin_foo_bar", true},
|
|
{"env123", true},
|
|
{"feature_PUP_1234", false},
|
|
{"UPPER", false},
|
|
{"has-dash", false},
|
|
{"has.dot", false},
|
|
{"", false},
|
|
}
|
|
for _, tc := range tests {
|
|
if got := ValidEnvironmentName(tc.name); got != tc.want {
|
|
t.Errorf("ValidEnvironmentName(%q) = %v, want %v", tc.name, got, tc.want)
|
|
}
|
|
}
|
|
}
|