func testRegister(t test.Tester) { var oldState = struct { abortOnMisuse bool debugRegistration bool useAggressiveSanityChecks bool }{ abortOnMisuse: abortOnMisuse, debugRegistration: debugRegistration, useAggressiveSanityChecks: useAggressiveSanityChecks, } defer func() { abortOnMisuse = oldState.abortOnMisuse debugRegistration = oldState.debugRegistration useAggressiveSanityChecks = oldState.useAggressiveSanityChecks }() type input struct { name string baseLabels map[string]string } var scenarios = []struct { inputs []input outputs []bool }{ {}, { inputs: []input{ { name: "my_name_without_labels", }, }, outputs: []bool{ true, }, }, { inputs: []input{ { name: "my_name_without_labels", }, { name: "another_name_without_labels", }, }, outputs: []bool{ true, true, }, }, { inputs: []input{ { name: "", }, }, outputs: []bool{ false, }, }, { inputs: []input{ { name: "valid_name", baseLabels: map[string]string{"name": "illegal_duplicate_name"}, }, }, outputs: []bool{ false, }, }, { inputs: []input{ { name: "duplicate_names", }, { name: "duplicate_names", }, }, outputs: []bool{ true, false, }, }, { inputs: []input{ { name: "duplicate_names_with_identical_labels", baseLabels: map[string]string{"label": "value"}, }, { name: "duplicate_names_with_identical_labels", baseLabels: map[string]string{"label": "value"}, }, }, outputs: []bool{ true, false, }, }, { inputs: []input{ { name: "duplicate_names_with_dissimilar_labels", baseLabels: map[string]string{"label": "foo"}, }, { name: "duplicate_names_with_dissimilar_labels", baseLabels: map[string]string{"label": "bar"}, }, }, outputs: []bool{ true, false, }, }, } for i, scenario := range scenarios { if len(scenario.inputs) != len(scenario.outputs) { t.Fatalf("%d. len(scenario.inputs) != len(scenario.outputs)") } abortOnMisuse = false debugRegistration = false useAggressiveSanityChecks = true registry := NewRegistry() for j, input := range scenario.inputs { actual := registry.Register(input.name, "", input.baseLabels, nil) if scenario.outputs[j] != (actual == nil) { t.Errorf("%d.%d. expected %s, got %s", i, j, scenario.outputs[j], actual) } } } }