Skip to content

Commit

Permalink
[chore][config/configopaque] Move implementation checks to test files (
Browse files Browse the repository at this point in the history
…#9430)

**Description:**
Move implementation checks to test files. Reduces dependencies of the
configopaque package.
  • Loading branch information
atoulme authored Jan 30, 2024
1 parent 39d2a0a commit 50132d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 0 additions & 9 deletions config/configopaque/opaque.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package configopaque // import "go.opentelemetry.io/collector/config/configopaque"

import (
"encoding"
"fmt"
)

Expand All @@ -14,31 +13,23 @@ type String string

const maskedString = "[REDACTED]"

var _ encoding.TextMarshaler = String("")

// MarshalText marshals the string as `[REDACTED]`.
func (s String) MarshalText() ([]byte, error) {
return []byte(maskedString), nil
}

var _ fmt.Stringer = String("")

// String formats the string as `[REDACTED]`.
// This is used for the %s and %q verbs.
func (s String) String() string {
return maskedString
}

var _ fmt.GoStringer = String("")

// GoString formats the string as `[REDACTED]`.
// This is used for the %#v verb.
func (s String) GoString() string {
return fmt.Sprintf("%#v", maskedString)
}

var _ encoding.BinaryMarshaler = String("")

// MarshalBinary marshals the string `[REDACTED]` as []byte.
func (s String) MarshalBinary() (text []byte, err error) {
return []byte(maskedString), nil
Expand Down
9 changes: 9 additions & 0 deletions config/configopaque/opaque_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package configopaque // import "go.opentelemetry.io/collector/config/configopaque"

import (
"encoding"
"encoding/json"
"fmt"
"testing"
Expand All @@ -13,6 +14,14 @@ import (
"gopkg.in/yaml.v3"
)

var _ encoding.TextMarshaler = String("")

var _ fmt.Stringer = String("")

var _ fmt.GoStringer = String("")

var _ encoding.BinaryMarshaler = String("")

func TestStringMarshalText(t *testing.T) {
examples := []String{"opaque", "s", "veryveryveryveryveryveryveryveryveryverylong"}
for _, example := range examples {
Expand Down

0 comments on commit 50132d6

Please sign in to comment.